Thursday, 8 August 2019

GIT: HOW TO LIST BRANCHES(LOCAL/REMOTE)

Git is the best known distributed version control system at the moment. Sometimes you may require to list available branches within your git repository. In this post, we will see different ways to list available branches.
As we are aware GIT is distributed version control system, that said it has replicas of data locally and remotely repositories. This concept of remote and local applicable to branches as well. We can create local branches and do our work locally and once we are confident we can push those changes by creating a remote branch with the same name. This post is bit details on listing branches with examples for people who are new to git and experienced alike.
The listing of git branches has total three answers with the above explanation. Below are those three type of git branches.
Git list local branches
Git list only remote branches
Git list all branches

LIST ALL LOCAL GIT BRANCHES

git branch
Example:
surendra@linuxnix:~/code/sh/gittraining$ git branch
first_branch
* master
In the above output if you observe we have two branches locally available and master is my present branch(* indicates present branch) where I am located.
Note: We can execute git branch from any directory with in a repository.

LIST ALL REMOTE GIT BRANCHES

git branch -r
-r is for listing any remote branches our git knows.
Example:
surendra@linuxnix:~/code/sh/gittraining$ git branch -r
origin/HEAD -> origin/master
origin/master

LIST ALL REMOTE AND LOCAL GIT BRANCHES

git branch -a
Example:
surendra@linuxnix:~/code/sh/gittraining$ git branch -a
first_branch
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
Note: If you observe above output, the coloring indicates remote(orange) and local branches(green)

0 comments:

Post a Comment