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:
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:
Step 3: Verification
Next, verify the newly created branch through the following command:
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:
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:
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:
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.