Git List Branches

As a popular source code versioning tool git provides different ways to list branches. Branches are used to develop different features by different developers and then merge with the main branch for the product. First, a new branch is created from the main branch where new features will be developed for. The new feature and code development and testing are done in the newly created branch. Then the new branch is merged with the main branch in order to add new features. At the same time, multiple branches can be created and developed at the same time. Also, there is no need to merge different branches at the same time.

List Current Branch

The git command provides the status command which lists the current git status with the branch information.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

From the output, we can see that we are currently in the master branch with the origin/master .

List Local Branches

The git branch command is used to list local branches. Branches can be created locally or remotely. Developers generally prefer local branches which do not affect the remote repository. The local branch only exists in the current system.

$ git branch

List Remote Branches

Git can be also used to store branches remotely. We can list remote git branches by using the git branch -r command like below.

$ git branch -r

List Local and Remote Branches

As stated previously a git branch can be stored locally or remotely. We can list both local and remote branches by using the git branch -a command like below.

$ git branch -a

Leave a Comment