git fetch
git
Usage
git fetch [--all] [--prune] [<remote> [<branch>]]Downloads new commits without touching your files or branch, so a merge or rebase still has to follow, and branches deleted on the server linger until --prune.
Common flags
| Flag | Meaning |
|---|---|
| --all | from every remote |
| --prune | delete tracking refs whose branch is gone on the server |
| --tags | also fetch tags |
| --unshallow | fill in the history a --depth clone left out |
| --depth <n> | deepen a shallow clone by n commits |
| -f | update a ref even when it is not a fast-forward |
Examples
git fetch --all --prunerefreshes every remote and clears dead branches
git fetch origin mainupdates origin/main without touching your files
git fetch --unshallowturns a shallow clone into a full one
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git fetch do?
Downloads new commits without touching your files or branch, so a merge or rebase still has to follow, and branches deleted on the server linger until --prune.
Q. How do I type it?
git fetch [--all] [--prune] [<remote> [<branch>]] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-fetch