How to Show All Branches in Git: Local and Remote

When working with Git, especially in collaborative environments, it’s important to keep track of the various branches in your repository. Whether you’re switching branches, cleaning up old ones, or reviewing your team’s work, knowing how to list all branches โ€” both local and remote โ€” is essential.

This quick guide will show you how to display all Git branches using a few simple commands.


๐Ÿ” List Local Branches

To see all branches that exist locally on your machine:

git branch

Example Output:

* main
  feature/login
  bugfix/api-error
  • The * indicates the currently checked-out branch.
  • These are the branches youโ€™ve created or checked out locally.

๐ŸŒ List Remote Branches

To view branches that exist on the remote repository (e.g., GitHub or GitLab):

git branch -r

Example Output:

origin/HEAD -> origin/main
origin/feature/login
origin/bugfix/api-error

This shows the branches available on the remote, typically prefixed with origin/.


๐Ÿ”„ List All Branches (Local + Remote)

To display all branches โ€” both local and remote โ€” in one list:

git branch -a

Example Output:

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

This is especially useful for getting a complete picture of your repositoryโ€™s structure.


๐Ÿ”„ Keep Remote Branches Updated

To make sure youโ€™re seeing the latest remote branches:

git fetch --all

This updates your local copy of the remote branch references, ensuring you can view the most current state of the repository.


๐Ÿงน Optional: Prune Deleted Remote Branches

To remove references to branches that have been deleted from the remote:

git remote prune origin

This helps keep your remote branch list clean and accurate.


โœ… Summary

CommandDescription
git branchList local branches
git branch -rList remote branches
git branch -aList all branches (local + remote)
git fetch --allUpdate remote branch information
git remote prune originClean up deleted remote branches

Conclusion

Understanding how to view all branches in Git is fundamental for navigating any Git-based workflow. Whether you’re merging, switching, or cleaning up branches, these commands will give you full visibility into your project’s structure.

Sharing Is Caring:

Leave a Comment