What is Branch in Git

Aash Gates
2 min readDec 16, 2022

--

Git Branch

In Git, a branch is a separate line of development. When you create a branch, you are creating a copy of the code at a specific point in time, and you can then make changes to the code in that branch without affecting the main branch (usually called “master”).

For example, let’s say you are working on a project, and you want to add a new feature. Instead of making changes to the main codebase directly, you can create a new branch for the feature. This way, you can work on the feature without affecting the main codebase, and you can easily switch between the main codebase and the feature branch as needed.

When you are finished working on the feature and you want to merge your changes back into the main codebase, you can do so by creating a “pull request,” which is a request to merge your changes from the feature branch into the main branch. Other team members can review the pull request, discuss any changes, and then merge the feature branch into the main branch once it is ready.

Using branches in Git allows you to work on multiple features concurrently, and it makes it easier to manage and track changes to your codebase.

Branch Creation

To create a new branch in Git, you can use the “git branch” command followed by the name of the new branch. For example:

git branch feature-x

This will create a new branch called “feature-x” based on the current state of the code. To switch to the new branch and start making changes, you can use the “git checkout” command followed by the name of the branch:

git checkout feature-x

Once you are finished working on the feature and you want to merge your changes back into the main codebase, you can create a “pull request” in your version control system (such as GitHub or GitLab). A pull request is a request to merge your changes from the feature branch into the main branch. Other team members can review the pull request, discuss any changes, and then merge the feature branch into the main branch once it is ready.

Using branches in Git allows you to work on multiple features concurrently, and it makes it easier to manage and track changes to your codebase. It also helps to prevent conflicts when multiple people are working on the same codebase, as each person can work on their own branch and then merge their changes into the main codebase when they are ready.

--

--

Aash Gates

VMware Certified Technical Associate-NV |Certified OCI Foundation Associate|Diploma in CSE|Bachelors in ISE|Certified Phish-Spotting Ninja