keepcalculator

06 Numbers and Powers

Git List Remote Branches: Commands and Troubleshooting

Card No. 06·36358 · Updated · Standard formula, shown below

To list remote branches in Git, run git branch -r. To see both local and remote-tracking branches together, use git branch -a; these commands show branch references already recorded in your local repository, not necessarily every branch currently on the server.

What Git Means by a Remote Branch

A remote branch is a branch that exists in a repository hosted elsewhere, such as a shared team repository. In your local clone, Git normally represents its known remote branches as remote-tracking branches. A name such as origin/main is a local reference recording where Git last observed the remote’s main branch.

This distinction matters: origin/main is not a live connection to the server, and it is not usually a branch you commit to directly. You create or switch to a local branch to do work, then fetch or push to exchange updates with the remote repository.

List Remote Branches with Git

Run the command from inside a Git working tree:

git branch -r

Typical output might look like this:

  origin/HEAD -> origin/main
  origin/main
  origin/feature/search
  upstream/release

Each ordinary line is a remote-tracking branch. The line origin/HEAD -> origin/main is a symbolic reference indicating the remote’s default branch; it is not an additional branch to check out under the name origin/HEAD.

To include local branches in the same listing, run:

git branch -a

This displays local branches, such as main, alongside remote-tracking names, such as remotes/origin/main. The remotes/ prefix in this output helps identify a remote-tracking reference; it is not normally part of the name used with commands such as git switch.

Refresh the List with Fetch

Git’s branch listing reflects references stored locally. If someone has recently created or deleted a branch on the server, refresh your repository’s remote-tracking references first:

git fetch --all --prune
  • --all fetches from all configured remotes, rather than just one.
  • --prune removes remote-tracking references for branches that no longer exist on the remote, subject to your fetch configuration.

Then list the updated references with git branch -r. If you only need to update one remote, for example origin, use git fetch origin --prune. Fetch updates references and downloads needed data; it does not merge changes into your current branch or alter your checked-out files.

A plain git branch -r does not contact the server. Therefore, a branch created moments ago may not appear until you fetch. Likewise, a deleted branch can remain in the listing until pruning removes its stale tracking reference.

See the Remote and Branch Details

When a repository has more than one remote, the remote name is the part before the slash: origin/feature/search belongs to origin, while upstream/release belongs to upstream. To see configured remotes and their URLs, run:

git remote -v

To list branches reported by a server directly, use git ls-remote --heads. For example:

git ls-remote --heads origin

This queries the remote and prints branch references with their commit IDs. It is useful when you want to check what the server advertises without relying on your existing remote-tracking list. It does not update that list; use git fetch when you want to refresh your local references.

For a more informative local listing, git branch -vv shows local branches and, where configured, their upstream branches and ahead/behind status. To view recent commit information for remote-tracking branches, try git branch -r -v. These are local views and can be out of date until you fetch.

Check Out a Remote Branch

To work on a remote branch, create a local branch that tracks it. A common modern command is:

git switch --track origin/feature/search

Git creates a local branch, usually named feature/search, and configures it to track origin/feature/search. If the local branch already exists, switch to it with git switch feature/search. The older equivalent for creating a tracking branch is git checkout --track origin/feature/search.

When several remotes have branches with the same short name, specify the intended remote explicitly. For example, origin/topic and upstream/topic are distinct remote-tracking branches. Avoid assuming that a branch shown under one remote is present under another.

Common Problems and Misconceptions

  • No branches appear: The repository may have no fetched branch references, or the remote may have no branches. Check git remote -v, then try git fetch --all.
  • A new branch is missing: Fetch from the relevant remote. The listing is not automatically refreshed every time you run git branch -r.
  • A deleted branch still appears: Run git fetch --prune or git remote prune origin to clean up stale references for the relevant remote.
  • You see origin/HEAD: It is a pointer to the remote’s default branch, not a separate working branch.
  • You cannot commit on origin/main: That is a remote-tracking reference. Switch to a local branch, or create one that tracks it.

If a fetch fails, check that the remote URL is correct and that your network and access permissions allow contact with it. A remote-tracking branch can also be absent because the remote’s fetch refspec is configured to fetch only selected branches. The output of git remote -v helps identify which remote to investigate.

Frequently Asked Questions

What is the command to list all remote branches in Git?
Use git branch -r for remote-tracking branches. Run git fetch --all --prune first if you need to refresh the list.

How do I list local and remote branches together?
Run git branch -a. Local branches appear by their local names, while remote-tracking branches appear beneath a remotes/ prefix.

Does git branch -r show every branch on the server?
Not always. It shows remote-tracking references currently stored locally, which may be stale or limited by fetch configuration. Use git ls-remote --heads origin to query a remote directly.

How do I update the remote branch list?
Run git fetch --all --prune to fetch from configured remotes and remove stale tracking references, then run git branch -r.

How do I switch to a remote branch?
Use git switch --track origin/branch-name to create and switch to a local tracking branch. Replace the example remote and branch with the names in your listing.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →