| 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:
git branchSample output:
bugfix/issue-1
feature/login
* mainThe 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:
git branch --show-currentmainIf 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:
git status -sb## mainThe 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:
git fetch originThen list remote-tracking branches:
git branch -rorigin/feature/login
origin/mainThese 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.
git branch -abugfix/issue-1
feature/login
* main
remotes/origin/feature/login
remotes/origin/mainLocal 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:
git branch -vbugfix/issue-1 3e6a7cd Fix issue 1
feature/login 0bd80f9 Add login feature
* main 3e6a7cd Fix issue 1Add upstream tracking with -vv:
git branch -vvbugfix/issue-1 3e6a7cd Fix issue 1
feature/login 0bd80f9 [origin/feature/login] Add login feature
* main 3e6a7cd [origin/main] Fix issue 1main 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:
git ls-remote --branches origin0bd80f94c3775eccbf888e1eb4cca9844dfaa076 refs/heads/feature/login
3e6a7cdf4d9cbb65f10287a4cd5e1eece1547358 refs/heads/maingit 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:
git remote -vorigin 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):
git branch --list '*feature*'feature/loginSort branches by the date of the latest commit reachable at each branch tip, newest first:
git branch --sort=-committerdatebugfix/issue-1
feature/login
* mainThis 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:
git branch --mergedbugfix/issue-1
* mainEvery 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:
git branch --no-mergedfeature/loginfeature/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:
git fetch --pruneGit may print the fetched or pruned refs. After it finishes, list remote-tracking branches again:
git branch -rorigin/mainorigin/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
- Git branch documentation
- Git remote documentation
- Git fetch documentation
- Git ls-remote documentation
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?
2. How do I list local branches in Git?
3. How do I list remote branches in Git?
4. How do I check the current branch in Git?
## main.
