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
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.
surendra@linuxnix:~/code/sh/gittraining$ git branch -r origin/HEAD -> origin/master origin/master
List all remote and local git branches
git branch -a
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)
In our next post, we will see how to merge two branches. For all git related post click on this link.
Latest posts by Surendra Anne (see all)
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018
- 15 iostat command examples in Linux/Unix - December 4, 2017
- How to Installing and Configuring Firewalld on Linux - November 29, 2017