Git List Branches: Local, Remote, and All Branches

Tested on RHEL 10.2 (Coughlan)
Package git 2.52.0
Applies to Any host with Git installed
Privilege Normal user
Scope List local, remote-tracking, and combined branch views with git branch, git fetch, git ls-remote, filter and sort flags, merged/unmerged lists, and prune for stale remote names. Not a full branch create, switch, or delete tutorial.
Related guides Git branch examples
Git fetch examples
Git delete branch
Git remote add examples
Git set upstream

Listing branches answers four common questions:

  • which branch names exist on your machine;
  • which remote branches Git already knows about locally;
  • how to see local and remote names in one view;
  • which branch is current and what each one tracks.

Each goal maps to a small set of git branch flags — or to git fetch when the remote-tracking list needs refreshing. Pick your goal in the table below, then jump to that section.


Choose the Right List Command

Your goal Command
Local branch names only git branch
Current branch name only git branch --show-current
Remote-tracking branches already fetched git branch -r
Local and remote-tracking names together git branch -a
Latest commit on each local branch git branch -v
Upstream tracking per local branch git branch -vv
Branch names on the server before fetch git ls-remote --branches origin
Names matching a pattern git branch --list '*pattern*'
Branches sorted by latest commit date git branch --sort=-committerdate
Branches already merged into current git branch --merged
Branches not merged into current git branch --no-merged
Drop deleted remote branch names git fetch --prune

Creating, switching, and deleting branches live in Git branch examples. This article focuses on reading branch lists.


List Local Branches

Scenario: you want every branch name that exists in your local repository.

From a repo with main, feature/login, and bugfix/issue-1:

bash
git branch

Sample output:

output
bugfix/issue-1
  feature/login
* main

The asterisk marks the branch checked out in this worktree — here main. A plus sign (+) means that branch is checked out in another linked worktree instead. Other names are local branches you can switch to with git switch branch-name.

When you only need the current branch name, not the full list:

bash
git branch --show-current
output
main

If git branch --show-current prints nothing, you are likely in detached HEAD state — it does not print HEAD. Confirm with git status -sb.

To see every local branch and which one is active, use git branch and look for the *. You can also read the branch from short status:

bash
git status -sb
output
## main

The first ## line identifies the current branch. Modified, staged, or untracked files appear on following lines.


List Remote-Tracking Branches

Scenario: you pushed or pulled recently and want branch names Git learned from origin.

Remote-tracking names look like origin/main. They update when you fetch — not automatically when someone pushes on the server.

Fetch the latest refs from origin:

bash
git fetch origin

Then list remote-tracking branches:

bash
git branch -r
output
origin/feature/login
  origin/main

These are names your local repo learned during git fetch — not a live read of the server. If a new branch appeared on the remote since your last fetch, it will not show here until you fetch again — see Git fetch examples.


List Local and Remote Names Together

Scenario: you want one combined view before choosing a branch to switch or delete.

bash
git branch -a
output
bugfix/issue-1
  feature/login
* main
  remotes/origin/feature/login
  remotes/origin/main

Local names appear without a prefix; remote-tracking branches stored in your local repository appear under remotes/origin/. The bugfix/issue-1 line is local only — it was never pushed, so there is no matching remotes/origin/bugfix/issue-1 entry.


Show Last Commit and Upstream Tracking

Scenario: branch names alone are not enough — you need the tip commit or which remote branch a local branch follows.

Verbose local list with latest commit hash and subject:

bash
git branch -v
output
bugfix/issue-1 3e6a7cd Fix issue 1
  feature/login  0bd80f9 Add login feature
* main           3e6a7cd Fix issue 1

Add upstream tracking with -vv:

bash
git branch -vv
output
bugfix/issue-1 3e6a7cd Fix issue 1
  feature/login  0bd80f9 [origin/feature/login] Add login feature
* main           3e6a7cd [origin/main] Fix issue 1

main and feature/login track origin/main and origin/feature/login. bugfix/issue-1 has no [origin/…] bracket because it has no upstream set — see Git set upstream when you need that link.


List Branches on the Remote Before Fetching

Scenario: git branch -r is missing a branch you see on the server, and you want to read remote heads without updating your local remote-tracking refs.

Query what the server advertises right now:

bash
git ls-remote --branches origin
output
0bd80f94c3775eccbf888e1eb4cca9844dfaa076	refs/heads/feature/login
3e6a7cdf4d9cbb65f10287a4cd5e1eece1547358	refs/heads/main

git branch -r shows what your local repo learned during fetch; git ls-remote --branches origin shows what the server advertises right now. This command does not create local branches or remotes/origin/* entries — run git fetch when you want those names in git branch -r.

Check which remote URL origin uses:

bash
git remote -v
output
origin	https://gitlab.devlab.io/stackforge/deploy-kit.git (fetch)
origin	https://gitlab.devlab.io/stackforge/deploy-kit.git (push)

Filter and Sort Branch Names

Scenario: the repo has many branches and you need a short list.

Match names containing feature using Git’s pattern filter (the --list flag avoids treating the pattern as a new branch name):

bash
git branch --list '*feature*'
output
feature/login

Sort branches by the date of the latest commit reachable at each branch tip, newest first:

bash
git branch --sort=-committerdate
output
bugfix/issue-1
  feature/login
* main

This sorts branches by the commit date of the commit each branch currently points to. It does not show when the branch itself was created or renamed. Deletion steps are in Git delete branch.


See Merged and Unmerged Branches

Scenario: you are cleaning up after merges and need to know what is already part of your current branch.

With main checked out and bugfix/issue-1 already merged into it:

bash
git branch --merged
output
bugfix/issue-1
* main

Every commit reachable from these branch tips is already included in your current branch. They may be cleanup candidates, but confirm the branch is no longer needed before deleting it.

List branches whose tips are not merged into the current branch:

bash
git branch --no-merged
output
feature/login

feature/login still points at commits that are not reachable from main in this example — typical for open feature work.


Remove Stale Remote Branch Names

Scenario: a teammate deleted feature/login on the server, but git branch -r still shows origin/feature/login.

After the remote branch is gone, prune stale remote-tracking refs:

bash
git fetch --prune

Git may print the fetched or pruned refs. After it finishes, list remote-tracking branches again:

bash
git branch -r
output
origin/main

origin/feature/login is gone from the remote-tracking list. Your local feature/login branch may still exist until you delete it locally — remote prune only cleans remote-tracking names, not local branch pointers. The git prune command is a different job again: it drops unreachable objects during garbage collection rather than stale branch names.


Troubleshooting

Symptom Likely cause Fix
New remote branch missing from git branch -r Local repo has not fetched yet git fetch origin, then git branch -r
Branch on server but not in -r Same as above, or wrong remote name git remote -v, then git fetch <remote>
Need live server list without fetch -r shows fetched remote-tracking refs only git ls-remote --branches origin
Deleted remote branch still listed Stale remote-tracking ref git fetch --prune or git remote prune origin
git branch --show-current prints nothing Detached HEAD Confirm with git status -sb; git switch main to return to a branch
-vv shows [gone] Upstream branch deleted on remote Fetch with prune, then fix upstream or delete local branch

References


Summary

Listing branches starts with what you need to see: local names, remote-tracking names, both together, or extra detail like the latest commit and upstream. git branch covers local work; -r and -a add remote-tracking views after your repo has fetched those refs.

When the remote list looks wrong, fetch before you trust git branch -r. Use git ls-remote --branches origin only when you need the server’s current branch list without updating local remote-tracking refs.

Verbose flags help day to day: -v for the tip commit, -vv for tracking, --merged and --no-merged for cleanup planning, and --sort=-committerdate when many branches clutter the screen. After teammates delete remote branches, git fetch --prune keeps git branch -r accurate.

For creating, switching, merging, and deleting branches, continue with Git branch examples — this page is the map of which list command fits each listing question.


Frequently Asked Questions

1. How do I list all branches in Git?

Run git branch -a to print local branch names and remote-tracking names such as origin/main in one list. Use git branch for local only and git branch -r for remote-tracking only.

2. How do I list local branches in Git?

Run git branch. The current branch is marked with an asterisk. Add -v for the latest commit on each branch, or -vv to include upstream tracking such as origin/main.

3. How do I list remote branches in Git?

Run git branch -r after git fetch to see remote-tracking branches your local repo learned from the server. To read branch names on the server right now without fetching, use git ls-remote --branches origin.

4. How do I check the current branch in Git?

Run git branch --show-current to print only the current branch name. Run git branch to see every local branch, with an asterisk next to the one you are on. git status -sb prints the current branch on the first line, such as ## main.

5. Why does git branch -r not show every branch on the server?

git branch -r shows remote-tracking refs from your last fetch, not a live server query. Run git fetch to refresh that list, or git ls-remote --branches origin to read what the server advertises now.

6. How do I remove stale remote branch names locally?

After teammates delete branches on the server, run git fetch --prune or git remote prune origin so origin/old-branch disappears from git branch -r.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)