Home·Terminal commands
Ad

Claim your crypto exchange bonus

Bonuses you get just for signing up. Terms are copied straight from each exchange.

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

FlagMeaning
--allfrom every remote
--prunedelete tracking refs whose branch is gone on the server
--tagsalso fetch tags
--unshallowfill in the history a --depth clone left out
--depth <n>deepen a shallow clone by n commits
-fupdate a ref even when it is not a fast-forward

Examples

git fetch --all --prune

refreshes every remote and clears dead branches

git fetch origin main

updates origin/main without touching your files

git fetch --unshallow

turns 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

QWhat 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.

QHow do I type it?

git fetch [--all] [--prune] [<remote> [<branch>]] — square brackets mark the parts you can leave out.

QHow 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