Git Foundations / Work With a Remote

Fetch and inspect incoming work

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

Look Before You Integrate

When a teammate pushes, their commits sit in the shared repository until you ask for them. You could pull them straight into your branch, but it is often worth looking first: what changed, who changed it, and whether it affects what you are doing.

git fetch downloads new commits from the remote without touching your work. You inspect them, then decide how to integrate them.

What Fetch Changes

git fetch updates your remote-tracking branches, such as origin/main, to match the remote. That is all. Your own branches, your staging area and the files in your folder stay exactly as they were. Git reports each update:

From /home/you/git-practice/team/shared
   4c1e2a0..9b7d3f1  main       -> origin/main

This is illustrative output; your path and IDs will differ. The line means origin/main moved from one commit to another.

Because fetching never changes your work, it is always safe to run.

Ahead, Behind and Diverged

git status compares your branch with its remote-tracking branch:

Message starts withMeaning
Your branch is up to dateSame commit as your last fetch saw
Your branch is behindThe remote has commits you do not
Your branch is aheadYou have commits not yet pushed
Your branch and 'origin/main' have divergedBoth have new commits

These messages describe the remote as of your last fetch. If you have not fetched, git status can say "up to date" while new commits are waiting in the shared repository.

Inspecting Incoming and Outgoing Commits

Two dots between branch names select the commits on the right that are not on the left:

git log --oneline main..origin/main   # incoming: on the remote, not on main
git log --oneline origin/main..main   # outgoing: on main, not yet pushed
git diff main origin/main             # what integrating would change in the files

Read main..origin/main as "what origin/main has that main lacks". Add --stat to git diff for a file summary.

When you are ready, integrate. git merge origin/main brings the fetched commits into your branch. That fetch-then-merge pair is exactly what git pull does, which the next lesson covers.

Exercise: Inspect Incoming Work Before Integrating

Asha adds a meeting schedule. As Ravi, you will find out about it, inspect it and only then bring it in.

Starting state: Git configured as in the configuration lesson. You will rebuild the team practice set so everyone starts from the same state.

  1. Rebuild the practice set. This replaces any ~/git-practice/team folder from the previous lesson:

    cd ~/git-practice
    rm -rf team
    mkdir team
    cd team
    git init --bare -b main shared.git
    git clone shared.git asha
    cd asha
    git config user.name "Asha Rao"
    git config user.email "asha@example.com"
    cat > README.md <<'EOF'
    # Team notes
    
    We meet on Mondays.
    Bring your laptop.
    EOF
    git add README.md
    git commit -m "Add team notes"
    git push -u origin main
    cd ..
    git clone shared.git ravi
    cd ravi
    git config user.name "Ravi Kumar"
    git config user.email "ravi@example.com"
    cd ..
    

    You end in ~/git-practice/team, with a shared repository and two clones that both have the "Add team notes" commit.

  2. As Asha, add a schedule and share it:

    cd asha
    cat > schedule.md <<'EOF'
    # Schedule
    
    Monday: planning
    Wednesday: review
    EOF
    git add schedule.md
    git commit -m "Add meeting schedule"
    git push
    
  3. As Ravi, check the status:

    cd ../ravi
    git status
    

    It says Your branch is up to date with 'origin/main'. That is out of date: Ravi's clone has not asked the shared repository since cloning.

  4. Fetch, then check again:

    git fetch
    git status
    

    Git reports main -> origin/main, and the status now says Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.

  5. Inspect the incoming work before integrating:

    git log --oneline main..origin/main
    git diff main origin/main
    ls
    

    The log names the incoming commit, "Add meeting schedule". The diff shows the new schedule.md. ls does not list it yet: fetch changed nothing in your folder.

  6. Integrate it:

    git merge origin/main
    ls
    git status
    

    The merge fast-forwards, schedule.md appears, and the status is up to date again.

Success: you named the incoming commit before integrating it, and your files did not change until the merge.

If something differs:

What you seeLikely causeNext step
git fetch prints nothingNothing new in the shared repositoryCheck that Asha's git push succeeded
main..origin/main lists nothing after fetchingThe commit is already in maingit log --oneline to look
Status still says up to date after Asha pushedRavi has not fetchedgit fetch, then git status
fatal: not a git repositoryYou are in ~/git-practice/team, not inside a clonecd ravi or cd asha
  1. Keep the practice set for the next lesson.

Independent task: now both sides have new work. Run this setup, which makes an unpushed commit in Ravi's clone and pushes a new commit from Asha's:

cat >> README.md <<'EOF'
Snacks are on Ravi this week.
EOF
git commit -am "Note who brings snacks"
cd ../asha
cat >> schedule.md <<'EOF'
Friday: demo
EOF
git commit -am "Add Friday demo"
git push
cd ../ravi

As Ravi, find out what is incoming and what is outgoing without integrating anything. Name each commit, and say what git status reports.

Check Your Understanding

  1. Why is git fetch safe to run at any time?
  2. Ravi's git status says he is up to date, yet Asha pushed ten minutes ago. How can both be true?

Answer and Reasoning

Independent task

git fetch
git status
git log --oneline main..origin/main
git log --oneline origin/main..main

git status says Ravi's branch and origin/main have diverged, with 1 and 1 different commits each. Incoming, in main..origin/main: "Add Friday demo". Outgoing, in origin/main..main: "Note who brings snacks". The next lesson shows how to integrate diverged work.

Understanding check

  1. Fetch only downloads commits and moves remote-tracking branches such as origin/main. It never changes your branches, your staging area or the files in your folder; those change only when you integrate.
  2. git status compares Ravi's branch with his clone's origin/main, which reflects the shared repository as of his last fetch. Until he fetches again, his clone does not know about Asha's push.

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