git merge

Using git merge to combine code from two different branches

The git merge command is especially useful for combining code from two different branches into one. You might find you've finished working on a new feature via a separate branch, and you want that feature to be added to your main branch ready to be made live.

You would run the following to switch to your main branch, then merge your changes in from your feature branch:

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ git merge my-new-feature
Updating 56aedbe..0dda643
 assets/images/cheese/edam.svg | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 assets/images/cheese/edam.svg

In the command output you'll see the original commit from your main branch, followed by the latest commit from your feature branch, then a list of changed files.

That's it, you've now combined the work in your feature branch with that in your main branch.

Proudly powered by Katapult. Running on 100% renewable energy.