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)
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)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018