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.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git merge: Usage, Options & Common CI Errors?
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 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

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card