Name

merge

Synopsis

git merge commit ...

Merge one or more other branches into the current HEAD. For each specified commit, Git calculates the set of changes on that branch that are not currently in HEAD and attempts to apply those changes to the current HEAD. If the changes cannot be applied successfully, Git will leave conflicts in the index, which you will need to resolve by hand (using an editor, git add, and git commit).

Almost always, you will supply exactly one commit. In some situations, you may wish to merge more than one branch at the same time; this is called an octopus merge and is allowed only if none of the merges cause any conflicts. It is equivalent to merging the given commits one by one, except that the merged result produces only one new commit.

You can override the merge strategy to be used, but this is almost never necessary. When more than one commit is specified, the only allowed strategy is octopus.

Normally, Git combines the branch histories so git log will show all the commits from all branches that have been merged. With --squash, it eliminates the history of the branches other than HEAD. This simplifies the git log output, but prevents successful merges from that branch in the future, so it is usually a bad idea.

Options

--no-commit
--squash
--log
--no-ff
-s (resolve|recursive|octopus|ours|subtree)
-m msg

Examples

To merge feature branches feature1 and feature2 into your current branch using an octopus merge:

$ git merge feature1 feature2 Already up-to-date with aa871d4ef9657e03b2ef7053dc13a16777955499 ...

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.