sync
git fetch
Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.
git fetch [<remote>] [<refspec>] Common flags
| Flag | Purpose |
|---|---|
| --all | Fetch from all configured remotes |
| --prune | Delete local refs for branches removed on the remote |
| --tags | Also fetch all tags |
| --depth <n> | Limit fetched history to n commits |
| --unshallow | Convert a shallow clone into a full one |
Examples
git fetch origin Update remote-tracking branches for origin
git fetch --all --prune Fetch every remote and clean up deleted branches
git fetch origin main:main Update local main from origin without checking out
Gotcha
Fetch does NOT update your working branch; you still need merge, rebase, or pull to integrate the new commits.
Related commands
git pull
Fetches from the remote and integrates the changes into the current branch, effectively 'git fetch' followed by 'git merge' (or rebase). Updates your working tree with upstream commits.
git remote
Manages the set of named remote repositories your local repo tracks, such as origin or upstream. Lets you add, rename, remove, or inspect remote URLs.
git push
Uploads local commits from a branch to a remote repository, updating the remote-tracking references. Requires push permission on the remote.