Git Tutorial 13 – What Is A Branch In Git?


As a part of GIT Tutorials End To End, we will learn about branching concepts of Git in this post.

Prerequisite posts

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

Why Branch?

Let’s visualize some scenarios which might help you to understand the necessity of branches.

You are a hardworking developer and asked to develop two features in a Sprint. You started writing code for the first feature by pulling the latest code from the master branch in your local repo. During development, you found a requirement gap and can’t continue development. Meanwhile, you would like to start coding for the second feature but you have incomplete/unstable code for the first feature in your local repo. You have multiple options here:-

  • Delete all code of first Feature.
  • Make a copy of all changes in different folder and then start working on second feature.
  • You can pull change from master again in a new local repo.

There might be many more and seriously I have used the above options when I was a beginner in git.

The best option for the above scenario will be Branching. You can save the incomplete code of the first feature in a branch and can continue developing the second feature in another branch. You can work on both features parallelly and independently. You can perform all git operations in branches. A branch can be created in multiple scenarios like a bug fix, feature development, experimental code or customized code for different environments etc.

Advantages of branches in Git

  • Parallel development of features independently. Codes can be reviewd and modified easily.
  • Feature developed in a branch can be merged easily to main branch.
  • Useful in quick bg fixes, experimeting codes etc.
  • Code from any branch can be pulled and pushed.

In fact in real-time “Branch” system is mostly used. For example – In a sprint-based development methodology, features are developed in individual branches by each developer and merged to the main branch after proper review. We will see more about branches in upcoming posts.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.

Leave a Reply

Your email address will not be published. Required fields are marked *