How to List Branches in Git: Local, Remote, and All

When managing a Git repository, it’s crucial to understand your branching structure — especially when working with multiple features, bug fixes, or collaborating in a team. Git makes it easy to list branches, whether they exist locally or on a remote server like GitHub or GitLab.

In this post, you’ll learn how to list all branches in Git, including local and remote branches, using simple terminal commands.


📍 List Local Branches

To see all branches that exist on your local machine, run:

git branch

Example Output:

* main
  feature/login
  hotfix/session-timeout
  • The * indicates the branch you are currently on.
  • These branches are available for immediate checkout and development.

🌐 List Remote Branches

To view branches that exist on the remote repository (like GitHub):

git branch -r

Example Output:

origin/main
origin/feature/login
origin/bugfix/payment-error

These are the branches hosted on the remote but not necessarily checked out locally.


🔀 List All Branches (Local + Remote)

To view all branches — both local and remote — use:

git branch -a

Example Output:

* main
  feature/login
  remotes/origin/main
  remotes/origin/feature/login

This gives you a complete picture of your project’s branches.


🔄 Update Remote References

Before listing remote branches, make sure your local repo has the latest information:

git fetch --all

This command updates your local references with the latest branches and changes from the remote.


🧹 Optional: Clean Up Deleted Remote Branches

To remove references to branches that were deleted from the remote:

git remote prune origin

This keeps your branch list clean and accurate.


✅ Summary of Commands

TaskCommand
List local branchesgit branch
List remote branchesgit branch -r
List all branchesgit branch -a
Fetch latest branchesgit fetch --all
Prune deleted remote branchesgit remote prune origin

🧠 Conclusion

Knowing how to list branches in Git is essential for navigating your codebase, collaborating with teams, and keeping your workflow organized. Whether you’re switching branches, reviewing code, or cleaning up stale branches — these commands are invaluable.

Sharing Is Caring:

Leave a Comment