git fetch

Download new commits, branches, and tags from the remote without changing your current files.

This command updates your local knowledge of the remote repository so you can see new work (commits, branches, tags) before deciding whether to merge or rebase it into your current branch.

This command contacts the default remote (usually origin), asks for all new references (branches, tags, remote-tracking branches like origin/main), downloads the missing commits and objects, and updates your remote-tracking branches without touching your working directory or current branch. With no extra flags, git fetch is safe because it never modifies your local branches directly; it just updates references like origin/<branch>. You can add a remote name and branch, e.g. git fetch origin main, where origin is the remote and main is the branch to fetch, which narrows the operation to that specific branch instead of all branches.

You can use git fetch --all to fetch from all configured remotes at once, git fetch --prune to remove remote-tracking branches that no longer exist on the server, and git fetch -p as a shorter way to write the same prune option. For debugging or automation, git fetch --dry-run shows what would be fetched without actually downloading anything, while git fetch --tags focuses on tags, and git fetch --depth <n> (e.g. --depth 1) fetches a shallow history, which can speed up cloning or updating large repositories.

Related commands that build directly on this behavior include git pull, which effectively runs git fetch followed by a merge or rebase into your current branch, and git remote -v, which shows which remotes git fetch will contact. After running this command, you often follow it with git log origin/<branch> or git diff <branch> origin/<branch> to inspect remote changes before integrating them.

Examples:

  • git fetch origin main
  • git fetch --all --prune
  • git fetch --depth 1 origin main
Manual page
git fetch
Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...