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
withgit branch
. - To create a local branch from a remote one:
git checkout -b local-name origin/remote-branch-name
π Summary
Task | Command |
---|---|
List local branches | git branch |
List remote branches | git branch -r |
List all (local + remote) | git branch -a |
Update remote refs | git fetch --all |