0
0
GitHow-ToBeginner · 3 min read

How to List All Branches in Git: Commands and Examples

To list all local branches in Git, use the command git branch. To see all branches including remote ones, use git branch -a.
📐

Syntax

The basic command to list branches is git branch. Adding -a shows all branches, including remote ones. You can also use git branch -r to list only remote branches.

bash
git branch

git branch -a

git branch -r
💻

Example

This example shows how to list local branches and then all branches including remote ones.

bash
$ git branch
* main
  feature-1
  bugfix

$ git branch -a
* main
  feature-1
  bugfix
  remotes/origin/main
  remotes/origin/feature-1
  remotes/origin/bugfix
Output
* main feature-1 bugfix * main feature-1 bugfix remotes/origin/main remotes/origin/feature-1 remotes/origin/bugfix
⚠️

Common Pitfalls

One common mistake is expecting git branch to show remote branches; it only shows local branches. Another is confusing git branch -r with git branch -a. The former shows only remote branches, the latter shows both local and remote.

bash
$ git branch
# Shows only local branches

$ git branch -r
# Shows only remote branches

$ git branch -a
# Shows both local and remote branches
📊

Quick Reference

CommandDescription
git branchList local branches
git branch -rList remote branches only
git branch -aList all branches (local + remote)

Key Takeaways

Use git branch to list local branches only.
Add -a to list all branches including remote ones.
Use git branch -r to see only remote branches.
Remember local and remote branches are different and shown by different flags.
Always check your current branch marked with an asterisk (*) in the list.