| by Arround The Web | No comments

Merge One Local Branch into Another Local Branch

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:

$cd "C:\Git"

Step 3: Create New Git Branch

Utilizing the “git branch” command along with the new branch name for creating a new Git branch:

$ git branch First-branch

To verify whether the branch is created or not, simply execute the “git branch” command:

$ git branch

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:

$ git checkout First-branch

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:

$ git checkout features

Step 6: Merge Branch

Lastly, merge the local branch into the currently opened local branch by utilizing the “git merge” command:

$ git merge First-branch

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.

Share Button

Source: linuxhint.com

Leave a Reply