Git/
Lesson

Working alone is easy. Working in a team is where Git shows its real value. Fetch and pull are your tools for staying synchronized with others' work. Understanding the difference between the two is crucial, one is safe, the other can create unexpected conflicts.

git fetch: look without touching

Fetch downloads everything from the remote, commits, files, branches, but modifies nothing in your working directory:

# Fetch from origin
git fetch origin

# Fetch from all remotes
git fetch --all
What fetch doesWhat fetch does NOT do
Downloads new commitsModify your current branch
Updates remote references (origin/main)Merge changes
Lets you inspect changes firstCreate conflicts

Review fetched changes

After a fetch, you can see what changed:

# See new commits on origin/main that you don't have locally
git log main..origin/main --oneline

# See the actual differences
git diff main..origin/main
AI pitfall
When you ask AI "how do I get the latest changes?", it almost always suggests git pull directly. This skips the review step entirely. On a shared project, always run git fetch first and inspect the incoming changes with git log or git diff. This prevents surprise merge conflicts and lets you understand what your teammates changed before it hits your working directory.
02

git pull: retrieve and merge

Pull does two things at once: fetch + merge. It is convenient but less controlled:

# Pull from origin (equivalent to: git fetch + git merge)
git pull

# Pull from a specific branch
git pull origin main

When you pull, Git:

  1. Fetches remote changes
  2. Automatically merges into your current branch
  3. Potentially creates conflicts to resolve

03

Pull with rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit.: keep clean history

Instead of creating a merge commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed., you can replay your commits on top of remote changes:

# Pull and rebase
git pull --rebase

Merge vs rebase: visual difference

With merge (git pull):         With rebase (git pull --rebase):

A---B---C---M                  A---B---C---D'---E'
     \     /                                 |
      D---E                             Your commits replayed

Result: history with           Result: linear history
merge commits                  (no extra merge commits)

Advantages of rebase:

  • Linear and clean history
  • No unnecessary merge commits
  • Easier to read and debug

When to avoid rebase:

  • On shared branches (it rewrites history)
  • If you have already pushed your commits

04

Fetch vs pull: when to use what?

SituationUse fetchUse pull
Want to review changes firstYesNo
Working alone on a branchEitherYes
Shared branch with active contributorsYesAfter reviewing
Quick sync on personal branchEitherYes
05

Manage pull conflicts

If pull creates conflicts:

git pull
# Auto-merging file.txt
# CONFLICT (content): Merge conflict in file.txt
# Automatic merge failed; fix conflicts and commit

# Open conflicted files and look for:
# <<<<<<< HEAD
# Your code
# =======
# Remote code
# >>>>>>> origin/main

# Resolve the conflict by choosing what to keep

# Mark as resolved
git add file.txt

# Complete the merge
git commit -m "Merge remote changes, resolve conflict in file.txt"
06

The safe workflow

# 1. Fetch to see what is new
git fetch origin

# 2. Check what changed
git log --oneline main..origin/main

# 3. If everything looks good, merge
git merge origin/main

# Or the shorter equivalent:
git pull
07

Strategies to avoid conflicts

  1. Pull before you push. Always get the latest before sending your work.
  2. Communicate with the team. If you are working on the same files, coordinate.
  3. Make atomic commits. Small, targeted commits are easier to merge than large ones.
  4. Use feature branches. Don't all work on main at the same time.
08

Quick reference

CommandActionModifies your files?
git fetchDownloads changesNo (safe)
git fetch --allDownloads from all remotesNo
git pullFetch + mergeYes
git pull --rebaseFetch + rebaseYes
git log main..origin/mainSee incoming changesNo
git diff main..origin/mainSee incoming diffsNo