How to Get All Branches in Git

Working with multiple branches is a fundamental part of using Git. Whether you’re trying to see what you have locally or what exists on the remote (like GitHub), Git provides simple commands to list all available branches.


🧭 1. List All Local Branches

To see branches available on your local machine, run:

git branch

This will output something like:

* main
  feature/login
  bugfix/header

The * indicates your current branch.


🌐 2. List All Remote Branches

To see branches that exist on the remote repository (e.g., GitHub), run:

git branch -r

Example output:

origin/HEAD -> origin/main
origin/main
origin/feature/payment

πŸ”„ 3. List All Local and Remote Branches Together

To view both local and remote branches, use:

git branch -a

This will show something like:

* main
  feature/ui
  remotes/origin/main
  remotes/origin/feature/api

πŸ” 4. Update Remote Branch Info

Sometimes the remote list is outdated. To refresh it:

git fetch --all

This updates your knowledge of all branches from the remote.


🧠 Pro Tips

  • To check which remote branches are not yet checked out locally, compare git branch -a with git branch.
  • To create a local branch from a remote one: git checkout -b local-name origin/remote-branch-name

πŸ“Œ Summary

TaskCommand
List local branchesgit branch
List remote branchesgit branch -r
List all (local + remote)git branch -a
Update remote refsgit fetch --all
Sharing Is Caring:

Leave a Comment