Working with multiple branches is a fundamental part of Git-based workflows. Whether you’re fixing a bug, developing a feature, or reviewing code, knowing which branch you’re on—and what branches exist—is essential.
In this blog, you’ll learn how to:
- Check your current branch
- List all local and remote branches
- Understand the purpose of each branch
✅ How to Check the Current Branch
To see which Git branch you’re currently working on, use:
git branch
Example Output:
dev
* main
feature/login
The *
indicates your current branch—in this case, main
.
📋 List All Local Branches
To see all branches that exist locally on your machine:
git branch
This shows a list of branches in your local Git repo.
🌐 List All Remote Branches
To list branches that exist on the remote (e.g., GitHub):
git branch -r
Example output:
origin/main
origin/dev
origin/feature/login
These are branches stored on the remote repository (
origin
is the default name for the remote).
🌎 List All Local and Remote Branches
To see both local and remote branches together:
git branch -a
Example output:
* main
dev
remotes/origin/main
remotes/origin/feature/login
🔁 Fetch Latest Branch Info from Remote
Before listing remote branches, it’s a good idea to run:
git fetch
This updates your local metadata with the latest branch information from the remote.
🧠 Bonus: Check Branch with Status
Want to check your current branch and see if there are uncommitted changes?
git status
This shows:
- The current branch
- Untracked or modified files
- Changes staged for commit
🧭 Summary of Commands
Task | Command |
---|---|
Check current branch | git branch |
List local branches | git branch |
List remote branches | git branch -r |
List all branches | git branch -a |
Update remote branch info | git fetch |
See current branch + changes | git status |
🔧 Best Practices
- Use descriptive branch names like
feature/signup
,bugfix/navbar
, orhotfix/crash
. - Keep your local branch list clean by deleting stale branches:
git branch -d branch-name