Git Foundations / Work With a Remote

Remotes and cloning

Lesson 23 of 33. Open to read. No account needed.

Sharing Work Through a Remote

So far every repository has lived in one folder used by one person. Teams share work through a remote: another repository that everyone sends commits to and gets commits from. On a real team the remote usually sits on a hosting service. In this module it is a folder on your own computer, which lets you practise every step of collaboration with no account, no network and nothing to pay for.

You will play two collaborators, Asha and Ravi, each with their own copy of the project. This practice set stays in place for the rest of the module.

The Pieces

Three folders inside git-practice/team: shared.git, a bare repository holding history only, and two clones, asha and ravi, each with origin set to shared.git. Push arrows carry commits up to shared.git; fetch and pull arrows carry them down to each clone.

  • shared.git is a bare repository: it holds the history but has no working tree, so there are no project files to edit in it. Nobody works there; it exists only to be pushed to and fetched from. A bare repository's folder name usually ends in .git.
  • asha and ravi are clones: complete repositories, each with its own working tree and full history, created with git clone.
  • In each clone, origin is the name for the remote it was cloned from. git clone sets this up for you.

Commits travel only through the shared repository. Asha pushes her commits to it, and Ravi pulls them from it. The next lessons look at fetching, pulling and pushing one by one; this lesson uses them just enough to see work move between the clones.

Remote-Tracking Branches

A clone remembers where each branch of the remote was the last time it checked, in a remote-tracking branch. origin/main is your clone's record of main on origin. You do not commit on it; Git updates it when you fetch, pull or push.

git remote -v      # remotes and their locations
git branch -a      # local branches and remote-tracking branches

git remote -v lists origin twice, once for fetching and once for pushing. git branch -a shows remote-tracking branches as remotes/origin/main, and git status compares your branch with it, for example Your branch is up to date with 'origin/main'.

Exercise: Two Collaborators on One Computer

You will create the shared repository, clone it as Asha and as Ravi, and pass two commits between them.

Starting state: Git configured as in the configuration lesson.

  1. Create the shared repository:

    mkdir -p ~/git-practice/team
    cd ~/git-practice/team
    git init --bare -b main shared.git
    ls shared.git
    

    --bare makes a repository with no working tree. ls shows Git's own files, such as HEAD, config, objects and refs, and no project files.

  2. Clone it as Asha, and give this clone Asha's identity:

    git clone shared.git asha
    cd asha
    git config user.name "Asha Rao"
    git config user.email "asha@example.com"
    git status
    

    Git warns You appear to have cloned an empty repository., which is expected: there are no commits yet. The git config commands without --global apply only to this clone, so commits made here are by Asha.

  3. Make the first commit and share it:

    cat > README.md <<'EOF'
    # Team notes
    EOF
    git add README.md
    git commit -m "Add README"
    git push -u origin main
    

    Git reports * [new branch] main -> main: main now exists in the shared repository. The -u links your main to origin/main for later pushes and pulls; the push lesson explains it.

  4. Look at how the clone sees the remote:

    git remote -v
    git branch -a
    git status
    

    git remote -v shows origin with the path to shared.git. git branch -a lists main and remotes/origin/main. git status says your branch is up to date with origin/main.

  5. Clone the shared repository again as Ravi:

    cd ..
    git clone shared.git ravi
    cd ravi
    git config user.name "Ravi Kumar"
    git config user.email "ravi@example.com"
    git log --oneline
    

    Ravi's clone already has "Add README": cloning copied the full history.

  6. As Asha, make a second commit and push it:

    cd ../asha
    cat >> README.md <<'EOF'
    We meet on Mondays.
    EOF
    git commit -am "Add meeting day"
    git push
    
  7. As Ravi, pull it:

    cd ../ravi
    git pull
    git log --oneline
    

    git pull reports Fast-forward, and Ravi's log now has "Add meeting day" on top. Asha's commit reached Ravi through shared.git.

Success: both clones list origin pointing at shared.git, and the commit Asha pushed appears in Ravi's clone after a pull.

If something differs:

What you seeLikely causeNext step
fatal: repository 'shared.git' does not existYou ran git clone from the wrong foldercd ~/git-practice/team, then clone again
fatal: destination path 'asha' already exists and is not an empty directoryThe clone was made beforeUse the existing folder, or remove it and clone again
src refspec main does not match anyYou pushed before making a commitCommit first, then push
Already up to date. when Ravi pullsAsha's push did not happenRun git push in asha and read its output
Commits show the wrong authorThe git config commands were run in the wrong folderRun git config user.name inside each clone to check
  1. Keep the practice set. Do not delete ~/git-practice/team: the rest of this module uses it. The last lesson of the module removes it.

Independent task: send work the other way. As Ravi, add the line Bring your laptop. to README.md, commit it and share it, then bring it into Asha's clone. Show Asha's log, with Ravi's commit on top.

Check Your Understanding

  1. Why does shared.git have no working tree?
  2. In Asha's clone, what is origin/main, and when does it change?

Answer and Reasoning

Independent task

cat >> README.md <<'EOF'
Bring your laptop.
EOF
git commit -am "Ask everyone to bring a laptop"
git push
cd ../asha
git pull
git log --oneline

Run the first three commands in ravi. Asha's pull fast-forwards, and her log shows "Ask everyone to bring a laptop" on top. git log with --format or git show would name Ravi Kumar as its author.

Understanding check

  1. Nobody edits files in the shared repository. It exists only to store the history that the clones push to and fetch from, so it needs no checked-out files. Each person works in their own clone instead.
  2. It is Asha's clone's record of where main was in shared.git the last time her clone communicated with it. It changes only when she fetches, pulls or pushes, not when Ravi pushes: her clone does not know about Ravi's push until she asks.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy