What Is Branch?

Understanding Branches in Git with Diagrams

Recap of the branch concept

As explained in Chapter 1, a branch in Git is an independent line of development with a commit history. Each branch provides a dedicated recording space and has its own coding history (a line of commits).

Branches allow us to manage different versions of the same set of project files simultaneously. For example, one developer can work on adding a new promotion campaign feature while another developer is working on adding a new payment feature to the same web application.

Git provides a master branch as a default. (If the repository was initiated on the GitHub platform, the default branch may be called the main branch. Check master branch vs. main branch.) Unless you create a new branch, all your work is done on the master branch. The branch to create a new feature is typically called a topic branch.

Once development is completed in a topic branch, you can merge it with the master branch or its parent branch.

With the branching functionality, you can efficiently collaborate with others. Or you can even utilize branches by yourself to manage versions to develop different features simultaneously.

Branch illustrations

In this chapter, we'll show how branches are recorded. The main figure shows two illustrations. Both illustrations have codes like M1, M2, etc. Each of them is a representation of one commit.

  • Tree diagram: The tree diagram is used to describe how branches diverge and integrate along coding work. This tree diagram is commonl