AI Hints
Home›Git & GitHub Tutorial›Clone, Fetch and Pull
Git & GitHub · Lesson 60 of 144

Fetching Changes

Git fetch.

⏱ 2 min read▶ Video at 1:05:07🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

While you're working, your teammates push new commits to GitHub. Your computer doesn't know about them until you ask. Git fetch asks GitHub what's new, and downloads it, without changing your files.

Fetching Changes
From the video: Fetching Changes
  • Teammates push new commits
  • Your copy doesn't know yet
  • git fetch downloads, safely

git fetch

Our teammate Alex has pushed a commit. We run git fetch. Git downloads it, and shows origin main moving forward. Now status says, your branch is behind origin main by one commit. But our files haven't changed yet. Fetch only looks, it doesn't touch.

git
git fetch
From https://github.com/sam/my-site
   f63a17a..7893b97  main       -> origin/main
git status
On branch main
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean
git log --oneline -n 2
f63a17a (HEAD -> main) Link to about page
ef9c947 Add basic styles

Remote-tracking branches

Where did the new commit go? Into a special branch called origin slash main. It's your computer's memory of where main is on GitHub. Fetch updates it. Your own main stays put, until you decide to bring the changes in.

keyvalue
mainyour branch
origin/mainGitHub's main, as last fetched
git fetchupdates origin/main
Your filesuntouched

Summary

Git fetch downloads new commits into origin slash main, without changing your work. Next, bringing those commits into your branch.

Key takeaways
  • git fetch
  • Updates origin/main
  • Your files stay the same
Next up: Pulling Changes — git pull