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:

Show More Details About Local Branches

If you want more details like commit hashes and messages, use:

git branch -v

Example Output:

This gives:

List Local and Remote Branches Together

To show both local and remote branches:

git branch -a

This lists:

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

  1. 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.

  1. 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

git branch

Show details

git branch -v

Show all branches

git branch -a

Filter by name

git branch

Show merged branches

git branch --merged

Delete a branch in Git

git branch -d branch-name

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.