Video in progress

Junior 🌿 Git

What is the difference between `git fetch` and `git pull`?

git fetch downloads new commits from the remote but does not touch your branch. git pull does a fetch and then immediately merges (or rebases) into the current branch.

📖 Answer

fetch is safe: it only updates remote-tracking branches such as origin/main. Your local main and your working directory do not change.

git fetch origin
git log main..origin/main --oneline   # see what is new on the server
git merge origin/main                 # merge when we are ready

pull is fetch + merge in one command. It is convenient, but you merge without seeing what is coming in, and sometimes an unexpected conflict or merge commit appears.

In practice I often fetch first, especially on a branch that has been sitting for a while. For small, everyday updates, git pull is fine too.