git fetch
`git fetch` downloads new commits, branches, and tags from a remote repository, but does not merge them into your local branches. It lets you see what's changed before deciding to integrate it.
This makes fetch a safer alternative to pull when you want to review incoming changes first, using commands like `git log origin/main` or `git diff main origin/main`.
git fetch origin
git diff main origin/mainFetching updates
Run `git fetch origin` to download the latest commits and branches from the origin remote without changing your working files.
Reviewing fetched changes
After fetching, compare your branch to the remote with `git diff main origin/main` or `git log main..origin/main` to see new commits before merging.
git fetch originremote: Enumerating objects: 8, done.
a3f5c9e..9c2e1aa main -> origin/mainDownloads new commits from origin into the local origin/main tracking branch, without merging.
git log main..origin/main --oneline9c2e1aa Fix crash when cart is emptyShows commits that exist on the remote main but not yet on your local main branch.
Key points
- git fetch downloads changes without merging them.
- It updates remote-tracking branches like origin/main.
- You can review fetched changes before merging manually.
- git pull = git fetch + git merge combined.
