git fetch

The git fetch command downloads new commits, branches, and tags from a remote repository without changing your local working copy. It's a safe way to see what others have been working on before you decide to integrate their changes.

Fetching from a specific remote

To fetch updates from a named remote:

$ git fetch origin
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (4/4), done.
From github.com:your-org/your-repo
   a1b2c3d..e4f5g6h  main       -> origin/main
 * [new branch]      staging    -> origin/staging

Here, origin is the name of the remote (the default when you clone a repository). Git contacts the remote, downloads any new data, and updates your remote-tracking branches (like origin/main) — but your local main branch stays exactly where it was.

You can then inspect what changed with git log origin/main or git diff main origin/main before deciding to merge or rebase.

Fetching all remotes

If your project has multiple remotes (e.g. origin and upstream for a fork), you can fetch from all of them at once:

$ git fetch --all
Fetching origin
Fetching upstream

This is useful when you need to stay up to date with both the original repository and your fork.

Pruning deleted branches

Over time, branches get merged and deleted on the remote, but your local copy still has stale references to them. Use the --prune flag to clean these up:

$ git fetch --prune
From github.com:your-org/your-repo
 - [deleted]         (none)     -> origin/old-feature

This removes any remote-tracking branches that no longer exist on the remote. You can also set this to happen automatically on every fetch:

$ git config --global fetch.prune true

For more on cleaning up stale branch references, see How to clean up deleted branches.

Fetch vs pull

The key difference: git fetch only downloads — it never modifies your working copy or local branches. git pull is essentially git fetch followed by git merge (or git rebase, depending on your config).

Use fetch when you want to review incoming changes before integrating them. Use pull when you're ready to update your local branch immediately. For a detailed comparison, see Difference between git fetch and git pull.

Managing remotes

To see which remotes are configured, or to add and remove them, see git remote.

When you're ready to push your own changes back, DeployHQ can automatically deploy on every push — so fetching, reviewing, and merging upstream changes is the safe first step before your code goes live.