Git Checkout Remote Branch: How to Fetch and Track (with Examples)
Updated Jul 2026 · originally published Dec 2020 · Tested on Git 2.40+, Linux, macOS
Git checkout remote branch is the task of taking a branch that lives on a remote repository, such as one on GitHub or GitLab, and creating a local copy you can work on. Because Git only knows about branches it has downloaded, you first make your machine aware of the remote branch with git fetch, then check it out by name. This page shows both the modern and the classic commands, with examples for tracking, custom local names, and the errors people hit most.
Quick answer
To check out a remote branch, fetch first, then switch to it:
git fetch origin
git switch branch-name
If your Git is older than version 2.23, use the classic form instead:
git fetch origin
git checkout branch-name
Either way, when exactly one remote has a branch with that name, Git creates a local branch that tracks it. The rest of this page explains what each step does and covers the less obvious cases.
Why you need to fetch first
A plain git checkout or git switch works on branches Git already knows about locally. A branch that only exists on the remote is invisible until you download a reference to it. git fetch is what makes your machine aware of remote branches.
git fetch origin # origin is the name of the remote repository
git fetch downloads new commits and updates your remote-tracking branches, but it does not touch your working files or merge anything. That makes it a safe operation to run any time. The first fetch downloads everything and creates local references named after the remote branches; later fetches just bring in what has changed since you last ran it.
git fetch vs git pull
These two are often confused, and the difference matters.
git fetch only downloads. It updates your view of the remote and changes nothing in your working directory. git pull runs a fetch and then immediately merges the downloaded changes into your current branch, which can cause merge conflicts. Fetch when you just want to see what changed; pull when you are ready to integrate it, and ideally only after your own changes are committed.
Check out a remote branch (with tracking)
Once you have fetched, check out the branch by name. Modern Git uses git switch:
git switch bugfixes
Branch 'bugfixes' set up to track remote branch 'bugfixes' from 'origin'.
Switched to a new branch 'bugfixes'
The classic equivalent, which still works everywhere, is:
git checkout bugfixes
In both cases Git notices there is a remote branch called bugfixes, creates a local branch of the same name, and sets it to track the remote. Tracking is what lets Git tell you whether your local branch is ahead of, behind, or in sync with the remote, and it lets git pull and git push work without extra arguments.
To set tracking explicitly for a branch, use --track:
git checkout --track origin/feature-x
Branch 'feature-x' set up to track remote branch 'feature-x' from 'origin'.
Switched to a new branch 'feature-x'
Check out a remote branch with a different local name
Sometimes you want the local branch to have a different name from the remote one, or you need to be explicit about which remote branch to base it on. Use -b with checkout, or -c with switch, and name the remote branch:
# modern syntax
git switch -c urgent-fix origin/core/bugfixes/urgent
# classic syntax
git checkout -b urgent-fix origin/core/bugfixes/urgent
Branch 'urgent-fix' set up to track remote branch 'core/bugfixes/urgent' from 'origin'.
Switched to a new branch 'urgent-fix'
Without -b or -c, the new local branch takes the same name as the remote branch. With it, you choose the name, and the branch still tracks the remote you named.
Fixing “updating paths is incompatible with switching branches”
If you see this error:
fatal: git checkout: updating paths is incompatible with switching branches
it almost always means your local Git does not yet know about the remote branch. Fetch first, then retry:
git fetch origin
git switch branch-name
Pushing your changes back
After you commit work on a tracking branch, git push sends it to the remote so other people can see it. Because the branch is already tracking, no extra arguments are needed:
git push
Cleaning up stale remote branches
When a branch is deleted on the remote, your local references to it stick around until you prune them. The --prune flag removes references to branches that no longer exist upstream:
git fetch origin --prune
Command summary
| Task | Modern | Classic |
|---|---|---|
| Fetch remote changes | git fetch origin | git fetch origin |
| Check out a remote branch | git switch branch | git checkout branch |
| Custom local name | git switch -c local origin/remote | git checkout -b local origin/remote |
| Explicit tracking | git switch -c local --track origin/remote | git checkout --track origin/remote |
| Push a tracked branch | git push | git push |
| Prune deleted branches | git fetch --prune | git fetch --prune |
Related references
- Argo CD commands by function — GitOps delivery built on Git
- Ansible examples — automate deployments from your Git repos