You pull a repository, run git branch, and… the branch you expected just isn’t there. But when you check GitHub, it clearly exists. This is one of those moments that trips up even experienced developers.
What’s happening? The branch exists only on the remote, not in your local repository. Git isn’t broken—it’s just being precise about what it knows locally versus remotely.
What “Branch Exists Only on the Remote” Actually Means
When a branch exists on GitHub (or any remote), your local repo doesn’t automatically create a working copy of it. Instead, Git keeps a reference under origin/<branch-name>.
So if someone pushed a branch called feature/login-flow, your local repo won’t show it until you explicitly fetch or check it out.
Quick reality check
Run this:
1git branch -aYou’ll likely see something like:
1remotes/origin/feature/login-flowThat means the branch exists remotely—but you don’t yet have a local branch tracking it.
The Fastest Way to Start Using That Remote Branch
Here’s the command most developers end up needing:
1git checkout -b feature/login-flow origin/feature/login-flowThis does two things in one shot:
- Creates a new local branch
- Links it to the remote branch (tracking relationship)
Modern Git versions offer a shorter version:
1git switch --track origin/feature/login-flowOr even:
1git switch feature/login-flowGit is smart enough to detect the remote branch and set up tracking automatically.
Wait—What If You Don’t See the Remote Branch at All?
Here’s where things get interesting. If git branch -a doesn’t show the remote branch, your local repository simply hasn’t fetched it yet.
Run:
1git fetch originThis updates your local references to match the remote. After that, try:
1git branch -rYou should now see the missing branch.
Understanding Tracking Branches (This Part Matters)
A tracking branch is just a local branch that knows which remote branch it corresponds to.
Why does this matter?
git pullknows where to pull fromgit pushknows where to push to- You don’t have to specify remote/branch every time
You can verify tracking with:
1git statusOr more explicitly:
1git branch -vvA Common Mistake Developers Make
Some developers try this:
1git checkout feature/login-flowAnd get an error like:
error: pathspec 'feature/login-flow' did not match any file(s) known to git
The assumption is that Git should "just know" about the branch. But Git only knows what’s been fetched.
So the correct sequence is:
- Fetch remote branches
- Create or switch to a tracking branch
When Branch Names Drift Out of Sync
Sometimes the issue isn’t visibility—it’s mismatch.
Example:
- Remote branch:
feature/auth-ui - You try:
feature/auth
Git won’t guess. Use:
1git branch -rto confirm the exact name.
Cleaning Up Stale Remote References
Another subtle issue: branches that no longer exist remotely but still appear locally.
Fix that with:
1git fetch --pruneThis removes outdated references and keeps your repo clean.
Real-World Scenario
Imagine a teammate pushes a hotfix branch:
1hotfix/payment-timeoutYou pull the repo but don’t see it locally. You:
- Run
git fetch - Verify with
git branch -r - Switch using
git switch hotfix/payment-timeout
Now you’re working on the exact branch your teammate created—no guesswork, no duplication.
Why Git Works This Way
This behavior isn’t a flaw—it’s intentional.
Git avoids automatically creating local branches for every remote branch because:
- Repositories can have hundreds of branches
- Not all branches are relevant to every developer
- It keeps your local environment clean and intentional
Quick Command Cheat Sheet
- Fetch all remote branches:
git fetch origin - List remote branches:
git branch -r - List all branches:
git branch -a - Create tracking branch:
git checkout -b my-branch origin/my-branch - Modern switch command:
git switch --track origin/my-branch - Clean stale branches:
git fetch --prune
Wrapping It Up
If a GitHub branch exists only on the remote, it simply means your local repository hasn’t checked it out yet. Fetch it, create a tracking branch, and you’re good to go.
Once you internalize the difference between local and remote branches, these issues stop being confusing and start feeling predictable—which is exactly where you want to be when working with Git.