Creating and Merging Branches in Git

While working on Git, developers work on several repositories, each containing one or more branches. You can also create multiple branches for keeping different files and folders. It allows users to manage source code easily. However, sometimes they need to combine one Git branch with another branch. For this purpose, Git allows you to merge branches.

This article will illustrate:

How to Create/Make Branches in Git?

To create/make a new branch in Git, the “git branch <branch-name>” command can be utilized. Try out the below-provided steps for practical demonstration.

Step 1: Move to Required Repository

First, switch to the desired local repository by entering the “cd” command:

$ cd "C:\Git\ReposC"

Step 2: Create/Make New Branch

Then, type out the below-provided command along with the new branch name to create it. For instance, “alpha” is our new branch name:

$ git branch alpha

Step 3: Verification

Next, verify the newly created branch through the following command:

$ git branch

It can be observed that the new “alpha” branch has been created:

Alternatively, users can use the “git checkout -b <branch-name>” command to create a new branch and switch to it simultaneously:

$ git checkout -b beta

It can be seen that the above-stated command has created a new “beta” branch and switched to it simultaneously:

How to Merge Branches in Git?

To merge branches in Git, run the “git merge” command along with the “–no-ff” option and the desired branch name that needs to be merged:

$ git merge --no-ff beta

Here, the “–no-ff” option is utilized to create a commit message even if the branches are fast-forwarded, and “beta” is the target branch that we want to merge:

Then, verify whether the branches have been merged or not by checking the commit history:

$ git log --oneline

The below output indicates that the “beta” branch has been merged with the “master” branch:

That was all about creating and merging branches in Git.


To create/make a new branch, various commands can be utilized, such as the “git branch <branch-name>” command just creates a new branch, and the “git checkout -b <branch-name>” command creates/makes a new branch and switches to it at once. Moreover, users can use the “git merge <branch-name>” command to merge branches in Git. This article explained about creating and merging branches in Git.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.