EasyConcept

What is the difference between git fetch and git pull?

Technology:
Git
Experience:
Intern,
Junior
Topics:
Git

Quick answer

git fetch downloads new commits from the remote without changing your working branch; git pull runs a fetch and then merges (or rebases) those commits into your current branch.

Detailed explanation

git fetch updates your remote-tracking branches such as origin/main. Your own branch and working files are untouched, so it is always safe. You can then inspect what changed with git log main..origin/main before deciding how to integrate it.

git pull is git fetch followed by git merge by default. If your branch and the remote have both moved, it creates a merge commit or stops with conflicts. Many teams set git config pull.rebase true so pull replays your local commits on top of the remote instead, which keeps history linear.

A good habit before starting work is to fetch, review, then merge or rebase deliberately, rather than pulling blindly into a branch with uncommitted changes.

Example

bash
git fetch origin
git log --oneline main..origin/main   # what is new on the remote?
git merge origin/main                 # integrate when ready

# or in one step
git pull --rebase origin main

Key points

  • fetch: download only, never touches your branch
  • pull: fetch + merge (or rebase with --rebase)
  • Fetch first when you want to review incoming changes

Follow-up questions

  • GitEasy

    What is Git and how is it different from GitHub?

    Git is a distributed version control system that tracks changes to files on your machine; GitHub is a hosting service for Git repositories that adds collaboration features such as pull requests, code review and CI.

    Intern 路 Junior 路 Git
  • GitMedium

    What is the difference between git merge and git rebase?

    Both integrate changes from one branch into another: merge keeps both histories and joins them with a merge commit, while rebase rewrites your commits so they appear on top of the target branch, giving a linear history.

    Junior 路 Mid-level 路 Git
  • GitMedium

    How do you resolve a merge conflict in Git?

    Open the conflicted files, decide what the final code should be between the conflict markers, remove the markers, run the tests, then stage the files and continue the merge or rebase.

    Junior 路 Mid-level 路 Git
  • GitMedium

    What is the difference between git reset and git revert?

    git revert creates a new commit that undoes an earlier one and is safe on shared branches; git reset moves the branch pointer back to an earlier commit, effectively removing later commits from that branch鈥檚 history.

    Mid-level 路 Senior 路 Git