How to List Branches in Git
Git is a distributed version control system that allows you to keep track of changes in your program’s source code. It is a powerful tool to manage complex projects, and one of its core features is the ability to create multiple branches.
Branches in Git are essentially a pointer to a specific commit. They allow you to work on different features, bug fixes, or experiments in parallel without affecting the main codebase. It is essential to know how to list branches in Git to manage your codebase efficiently.
Here’s how you can list branches in Git:
1. Open your terminal or command prompt and navigate to your project’s directory.
2. Run the following command to list all the branches in your repository:
“`
git branch
“`
This command will list all the branches in your local repository. The current branch will be highlighted with an asterisk (*).
3. You can also use the -r option to list all the remote branches:
“`
git branch -r
“`
This command will list all the remote branches in your repository.
4. If you want to see the local and remote branches together, use the -a option:
“`
git branch -a
“`
This command will list all the local and remote branches in your repository.
5. To see the last commit on each branch, use the -v option:
“`
git branch -v
“`
This command will list all the branches with the last commit message on each branch.
6. If you want to filter the branches by a particular term, use the –list option followed by the search term:
“`
git branch –list feature/*
“`
This command will list all the branches that start with the “feature/” prefix.