How to Check All Branches in Git

Whether you’re working on a team or managing your own project, it’s important to understand how to view the available branches in a Git repository. Git allows you to create, list, switch, and manage branches easily — and checking branches is a common task.

In this post, you’ll learn how to check all branches in Git, including local and remote branches.


📂 What Are Git Branches?

A branch in Git is a lightweight, movable pointer to a commit. Branches are used to develop features, fix bugs, or experiment without affecting the main codebase.


🧾 Check Local Branches

To view local branches (branches that exist on your machine):

git branch

This will list all branches stored locally. The currently checked-out branch will be highlighted with an asterisk (*).

Example output:

* main
  feature/login
  bugfix/header

🌐 Check Remote Branches

To list remote branches (branches that exist on a remote like GitHub):

git branch -r

Example output:

origin/main
origin/feature/login
origin/develop

🌍 Check All Branches (Local + Remote)

To view both local and remote branches:

git branch -a

Example output:

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

This shows all branches tracked locally and remotely.


🔄 Update the List of Remote Branches

To make sure you’re seeing the most recent remote branches:

git fetch --all

This fetches the latest data from your remote repository without merging changes.


🧠 Summary of Commands

TaskCommand
List local branchesgit branch
List remote branchesgit branch -r
List all branchesgit branch -a
Fetch latest remote branchesgit fetch --all

🏁 Conclusion

Checking branches in Git is a simple but essential task. Whether you’re switching environments, merging changes, or collaborating with others, knowing how to view local and remote branches helps you stay in control of your codebase.

Sharing Is Caring:

Leave a Comment