How Do I List Only Local Branches in Git

Git is a popular and widely used version control system for software development.

It is used to keep track of changes made to a codebase, allowing developers to work on multiple features and bug fixes simultaneously.

One of the core concepts of Git is the use of branches.

In this tutorial, we’ll discuss what Git branches are and how to list only local branches in Git.


What are Git Branches?

In Git, a branch is a separate line of development.

When you create a new branch, you create a copy of the existing codebase, and you can make changes to it without affecting the main codebase.

Branches are a great way to work on new features or bug fixes independently, and when you are ready, you can merge your changes back into the main codebase.

Types of Git Branches

There are two types of Git branches: local branches and remote branches.

Local branches are branches that exist only on your local machine.

Remote branches are branches that exist on a remote server, such as a Git hosting service like GitHub or GitLab.

Listing Only Local Branches in Git

To list only local branches in Git, you can use the following command:

$ git branch

This command will display a list of all local branches in your Git repository, along with an asterisk (*) next to the current branch.

For example:

$ git branch
  branch-1
* branch-2
  branch-3

In this example, branch-2 is the current branch, and the other two branches (branch-1 and branch-3) are local branches in the repository.


Conclusion

Git branches are an essential concept for version control and allow developers to work on new features or bug fixes independently.

Understanding how to list only local branches in Git is a valuable skill for any software developer, and it can help you keep your repository organized and up-to-date.

By using the git branch command, you can easily view a list of all local branches in your Git repository.