Skip to content
Latchkey

git merge: Usage, Options & Common CI Errors

git merge combines the changes from another branch into your current branch.

Merging integrates work and, when histories diverged, can produce conflicts that a script must detect and stop on.

What it does

git merge brings the commits from a named branch into the current branch, creating a merge commit unless the merge can fast-forward.

Common usage

Terminal
git merge feature
git merge --no-ff feature       # always create a merge commit
git merge --squash feature      # combine changes, no merge commit
git merge --abort               # bail out of a conflicted merge

Options

FlagWhat it does
--no-ffForce a merge commit even if fast-forward is possible
--ff-onlyRefuse to merge if a merge commit is needed
--squashStage the combined result without committing
--abortRestore pre-merge state on conflict
-X ours / -X theirsAuto-resolve conflicting hunks one side

Common errors in CI

CONFLICT (content): Merge conflict in <file> / "Automatic merge failed; fix conflicts and then commit the result" - the merge stops with conflict markers. In automation, detect it (the command exits non-zero), then either resolve, choose a side with -X, or git merge --abort to leave history clean.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →