Git: Check Out a Remote Branch
Last updated
To work on a branch that exists on the remote but not yet on your machine, first git fetch so Git knows about it, then check it out. Modern Git makes this easy: git switch <branch> automatically creates a local branch that tracks the matching origin/<branch>.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git fetch origin | Download the remote's branches |
git switch feature | Create a local feature tracking origin/feature |
git checkout --track origin/feature | Older way to track a remote branch |
git switch -c local origin/feature | Track it under a different local name |
Worked example
Get a teammate's branch onto your machine.
| Step | Command | Result |
|---|---|---|
| 1 | git fetch origin | Git learns about origin/feature |
| 2 | git switch feature | Local feature created, tracking the remote |
| 3 | git pull | Keep it in sync going forward |
Git checkout remote branch FAQ
How do I check out a remote branch?
First run
git fetch origin so Git knows about the remote's branches, then git switch <branch>. Modern Git sees the matching origin/<branch> and automatically creates a local branch that tracks it. In older Git, use git checkout --track origin/<branch>.Why does git switch say the branch doesn't exist?
Usually because you haven't fetched yet - Git can only auto-create a tracking branch if it already knows about the remote branch. Run
git fetch origin (or git fetch --all) first, then git switch <branch> will work.How do I check out a remote branch under a different name?
Use
git switch -c <localname> origin/<branch> (or git checkout -b <localname> origin/<branch>). This creates a local branch with the name you choose that tracks the remote branch, handy when the remote name clashes with an existing local branch.What's the difference between fetch and checkout here?
git fetch only downloads the remote branches and updates your remote-tracking refs - it doesn't give you a working branch. Checking out (via git switch or git checkout) is what creates the local branch you actually work on. You fetch once, then check out.Can I practice this online?
Yes. Open the terminal playground to run these commands in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers working with remotes step by step.