0
0
Gitdevops~3 mins

Listing branches in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
When working with Git, you often create multiple branches to work on different features or fixes. Listing branches helps you see all the branches available in your project so you can switch or manage them easily.
When you want to see all the branches you have created locally in your project.
When you want to check which branch you are currently working on.
When you want to see all branches available on the remote repository.
When you want to clean up old branches by seeing which ones exist.
When you want to verify that a new branch was created successfully.
Commands
This command lists all local branches in your Git repository and highlights the current branch with an asterisk.
Terminal
git branch
Expected OutputExpected
main * feature-login bugfix-typo
This command lists all branches, both local and remote, so you can see everything available in your project.
Terminal
git branch -a
Expected OutputExpected
main * feature-login bugfix-typo remotes/origin/main remotes/origin/feature-login remotes/origin/bugfix-typo
-a - Show all branches, including remote-tracking branches
This command lists only the remote branches, which are branches stored on the remote server.
Terminal
git branch -r
Expected OutputExpected
origin/main origin/feature-login origin/bugfix-typo
-r - Show only remote branches
Key Concept

If you remember nothing else from this pattern, remember: use 'git branch' to see your local branches and 'git branch -a' to see all branches including remote ones.

Common Mistakes
Running 'git branch' expecting to see remote branches.
By default, 'git branch' only shows local branches, so remote branches won't appear.
Use 'git branch -a' to list all branches including remote ones.
Confusing the current branch indicator '*' as part of the branch name.
The asterisk '*' only marks the current branch and is not part of the branch name.
Ignore the '*' when typing branch names; it just shows which branch you are on.
Summary
Use 'git branch' to list all local branches and see which one is active.
Use 'git branch -a' to list all branches including remote ones.
Use 'git branch -r' to list only remote branches.