When working with Git, branches let you manage different lines of development in your project. Git allows you to create, switch, merge, and delete branches. If you want to see a list of all local branches, Git gives you simple and useful commands to do that.
In this guide, you'll learn how to view local branches, understand what each output means, and see common use cases.
What Are Local Branches in Git?
Local branches exist only on your computer. These are branches you create, work on, and update. They are separate from remote branches, which live on remote repositories like GitHub, GitLab, or Bitbucket.
For example, if you create a new feature branch:
git checkout -b feature-login
You're creating a local branch called feature-login
.
Show All Local Branches
To list all local branches in your Git project, use:
git branch
Example Output:
main
feature-login
bugfix-header
In this output:
- The
*
shows your current branch. - Other branches are listed below it.
Show More Details About Local Branches
If you want more details like commit hashes and messages, use:
git branch -v
Example Output:
feature-login a13f21c Fix login redirect
main b4cd21f Update README
bugfix-header c1a5d2b Fix header height
This gives:
- Branch name
- Last commit hash
- Commit message
List Local and Remote Branches Together
To show both local and remote branches:
git branch -a
This lists:
- Local branches (plain names)
- Remote branches (with
remotes/
prefix)
Example:
main
feature-login
remotes/origin/main
remotes/origin/feature-login
Filter Local Branches
To search for a branch name:
git branch | grep login
This filters local branches containing the word "login".
Check Last Commit Date for Local Branches
To list each branch with its last commit date:
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/); do
echo -e "$(git log -1 --format='%ci' $branch)\t$branch";
done | sort -r
This sorts branches by latest commit.
See Local Branches Merged into Current Branch
To see which local branches have been merged:
git branch --merged
To list local branches not merged yet:
git branch --no-merged
Common Issues
-
Not a Git Repository
If you see an error, check if you're inside a Git project:
git status
If it fails, cd into your Git project folder.
-
Remote vs Local Confusion
git branch -a
It shows both local and remote branches. Local ones have no prefix. Remote branches start with remotes/.
Summary
Here’s a quick reference table:
Task |
Command |
---|---|
List local branches |
|
Show details |
|
Show all branches |
|
Filter by name |
|
Show merged branches |
|
|
Final Thoughts
Git makes branch management easy. Knowing how to show local branches helps you keep your project clean and on track. Use these commands to stay organized, remove unused branches, and focus on the code that matters.