Git branch

963    Asked by KalyaniMalhotra in Devops , Asked on Nov 5, 2019
Answered by Vikash Kapoor

Branches in Git are nothing but pointers to a specific commit. Git generally prefers to keep its branches as lightweight as possible.

There are basically two types of branches viz. local branches and remote tracking branches.

A local branch is just another path of your working tree. On the other hand, remote tracking branches have special purposes. Some of them are:

They link your work from the local repository to the work on central repository.

They automatically detect which remote branches to get changes from, when you use git pull.

You can check what your current branch is by using the command:

git branch

The one mantra that you should always be chanting while branching is “branch early, and branch often”

To create a new branch we use the following command:

git branch

To checkout from current branch to another branch we use the following command:

git checkout

To the new branch and checkout the new branch at the same time.

git checkout -b[ branch_name]



Your Answer

Interviews

Parent Categories