Git is a powerful DevOps tool utilized for maintaining and managing DevOps projects and their source code. Git developers manage their code in different Git branches. More specifically, Git branches are the main component of Git used to test code, implement code in different contexts, define features in multiple ways, and many more. However, branches are further categorized into two categories: remote branches and local branches.
This blog will elaborate on the procedure for merging one local branch into another.
How to Merge One Branch into Another Local Branch?
Local branches exist on the local directory and are accessible through local machines only. To merge one local branch into another local branch, first, open the Git local repository and create a new branch. Next, merge that branch into any existing branch.
To merge a branch into another, look at the provided steps.
Step 1: Open Git Terminal
First, launch the βGit Bashβ terminal:
Step 2: Go to Git Local Repository
Go to the Git repository using the βcdβ command:
Step 3: Create New Git Branch
Utilizing the βgit branchβ command along with the new branch name for creating a new Git branch:
To verify whether the branch is created or not, simply execute the βgit branchβ command:
You can see that we have successfully created a new branch:
Step 4: Switch Branch
In order to switch to a newly created branch, check out the provided command:
Step 5: Switch to Existing Branch
Switch to any existing local branch in which you want to merge the newly created local branch. For instance, we have switched to the βfeaturesβ branch:
Step 6: Merge Branch
Lastly, merge the local branch into the currently opened local branch by utilizing the βgit mergeβ command:
The output displayed an βAlready up to dateβ message because we had already merged the local branch:
We have taught you how to merge one local branch into another local branch.
Conclusion
For merging a local branch into another, first, open the Git local repository. Next, create a new branch utilizing the β$ git branch <branch name>β command. Next, switch to that branch in which you want to the new branch using the Git βcheckoutβ command. After that, merge the branch using the β$ git merge <branch name>β command. In this write-up, we have illustrated the method to merge one branch into another local branch.