git
branch
remote
troubleshooting
version control

Remote branch is not showing up in git branch -r

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

If a remote branch does not appear in git branch -r, the problem is usually not with the command itself. Most often, your local repository has not fetched the branch yet, the remote configuration is filtering which refs are fetched, or the branch does not actually exist on the remote you think it does.

Start with a Fetch

git branch -r shows remote-tracking refs stored locally, not a live network listing from the server. So the first fix is usually:

bash
git fetch origin

Then check again:

That fetch step matters because remote-tracking refs are updated only when you ask Git to refresh them.

bash
git branch -r

If the branch was recently created on the server, fetching often solves it immediately.

Confirm the Branch Exists on the Remote

If fetch does not help, verify the remote actually has that branch. git ls-remote queries the remote directly:

bash
git ls-remote --heads origin

To search for one branch specifically:

bash
git ls-remote --heads origin feature/my-branch

If nothing is returned, the branch either was not pushed, was deleted, or is on a different remote.

Check Which Remote You Are Using

Many repositories have more than one remote, such as origin and upstream. Confirm the configured remotes:

bash
git remote -v

It is easy to fetch origin while the branch actually lives on upstream, or vice versa.

If needed:

bash
git fetch upstream
git branch -r

Inspect the Fetch Refspec

Sometimes the remote is configured to fetch only selected branches. In that case, the missing branch may exist remotely but still never appear locally.

Check the fetch configuration:

bash
git config --get-all remote.origin.fetch

A normal broad refspec often looks like this:

text
+refs/heads/*:refs/remotes/origin/*

If your refspec is narrow, update it or fetch the specific branch explicitly:

bash
git fetch origin feature/my-branch:refs/remotes/origin/feature/my-branch

That forces the remote-tracking branch into the local repository.

Clean Up Stale References Carefully

Stale refs can make remote branch state confusing. If branches were deleted or renamed, prune old remote-tracking refs:

bash
git remote prune origin

This does not download missing branches, but it removes outdated ones so your view of the remote becomes more accurate.

Permissions and Server Visibility

In some hosted setups, branch visibility can depend on authentication or repository permissions. If another user can see the branch but you cannot, confirm that you are authenticated to the correct repository and have access to that branch.

This is less common than fetch problems, but it does happen in enterprise Git hosting environments.

Common Pitfalls

The most common mistake is assuming git branch -r talks to the server live. It only shows what your local repository already fetched.

Another issue is looking at the wrong remote. A branch on upstream will not appear under origin/* unless you fetched from upstream.

People also forget about custom fetch refspecs. If the remote configuration is selective, some branches will never appear unless fetched explicitly.

Finally, do not confuse a local branch with a remote-tracking branch. A branch can exist locally without any corresponding origin/name ref, and vice versa.

Summary

  • Run git fetch first because git branch -r shows local remote-tracking refs.
  • Use git ls-remote --heads to verify the branch actually exists on the server.
  • Confirm you are fetching from the correct remote.
  • Check the remote fetch refspec if some branches never appear.
  • Prune stale refs so your local picture of the remote stays accurate.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.