Course outline · 0% complete

0/28 lessons0%

Course overview →

fetch vs pull

lesson 7-3 · ~9 min · 20/28

Look before you merge

git pull is convenient but blunt: whatever the remote has gets merged into your branch immediately, possibly rewriting files mid-thought or dropping a conflict in your lap at the worst time. When you'd rather see what the team changed before it lands in your files, engineers use the cautious half of pull, git fetch:

$ git fetch
remote: Counting objects: 5, done.
   c7d8e9f..f0e9d8c  main       -> origin/main

It downloads the remote's new commits and stops. Your files and your branches don't move. The news lands on a special read-only pointer named origin/main, a remote-tracking branch, meaning "where main was on the server, last time I checked."

Now you can inspect before accepting, using lesson 3-1 and 3-2 tools:

$ git log --oneline main..origin/main   # commits they have that I don't
$ git diff main origin/main             # exact line changes
$ git merge origin/main                 # bring them in when ready

fetch + inspect + merge is exactly git pull, just with a thinking step in the middle. Use pull when you trust and want the update now, fetch when you'd rather peek first.

Practice the careful sync. A teammate pushed something to origin overnight; inspect it before letting it touch your files.

Step 1/3: Download the remote's news without changing any of your branches or files.

~/recipe-book $ 

Quiz

Can git fetch ever change the files in your working directory or create a merge conflict?

Quiz

What does the name origin/main refer to?

Problem

Which command downloads the remote's new commits WITHOUT merging anything into your branch?