TOOL » GIT

Merge

Usage

Merges a source branch into the current branch.

shell
git merge OPTIONS SOURCE_BRANCH
OptionDescription
--squashPerform the merge but do not commit.
--no-ffForce creating a merge commit.
-s --strategyUse the given merge strategy.
--abortAbort a merge with conflicts.

Examples

Manual conflict resolution

Check if all conflicts were resolved by running:

shell
git grep -HE '<{7} HEAD'

To commit with the default merge message:

shell
git commit --no-edit

Automatic conflict resolution

Merge is actually done and files content change, but contents of ours or theirs is automatically chosen in case of conflict.

Example of merging master into a dev branch.

shell
git merge -Xours master    # In case of conflict: Keep ours, drop master
git merge -Xtheirs master  # In case of conflict: Drop ours, keep master

Overwrite branch

Using -s ours discards everything the other tree did, declaring our history contains all that happened in it.

In summary, no changes are done in the files. Only git changes.

Example: Suppose there are two branches keep and override. You want keep as is, and drop everything in override.

shell
git switch keep
git merge -s ours override
git switch override
git merge keep