Lessons · Git · fetch, then merge
fetch looks, pull changes
git fetch downloads new commits into origin/* and changes none of your branches. git pull is fetch followed by a merge (or rebase) into your branch.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Fetch is always safe, which makes it the way to look before you leap: see what arrived, then decide to merge or rebase. Pull does both at once and can produce a merge commit or a conflict.
How to think about it
Fetch, then compare: git log main..origin/main shows what they have that you do not. Merge or rebase on purpose. Use pull once you know what it will do.
Worked example
git fetch originDownloads new commits into origin/*; your branches do not move.
git log --oneline main..origin/mainWhat they have that you do not, before you decide anything.
git pullfetch, then merge (or rebase) origin/main into main.
Your turn
Download what is new without changing any of your branches.
git origin
Try it in a real repository
The trap
git pull can create a merge commit or a conflict on your branch. Fetch first, look, then merge or rebase on purpose.