How to Merge a Branch Into Another Branch in Git

Published Aug 10, 2021

Suppose we want to merge a branch featureBranch into our master branch.

Merge remote branch into local branch

If we don’t have a local copy of featureBranch and don’t want one, we can merge directly from the remote branch into our local master branch:

git checkout master
git merge origin/featureBranch

Merge local branch into local branch

If we don’t have a local copy of featureBranch and do want one, we can first create a local copy of the branch:

git checkout featureBranch

Creating a local branch like this is generally a solution to the fatal: branch-name - not something we can merge error in Git.

Finally, we can run a merge of the two local branches.

git checkout master
git merge featureBranch

More CLI Articles