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 mergeOptions
| Flag | What it does |
|---|---|
| --no-ff | Force a merge commit even if fast-forward is possible |
| --ff-only | Refuse to merge if a merge commit is needed |
| --squash | Stage the combined result without committing |
| --abort | Restore pre-merge state on conflict |
| -X ours / -X theirs | Auto-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
git rebase: Usage, Options & Common CI Errorsgit rebase replays commits onto a new base to keep history linear. Reference for -i, --onto, --continue, --ab…
git pull: Usage, Options & Common CI Errorsgit pull fetches from a remote and integrates the changes. Reference for --rebase, --ff-only, and the merge-c…
git cherry-pick: Usage, Options & Common CI Errorsgit cherry-pick applies the changes from specific commits onto the current branch. Reference for -x, -n, rang…
git diff: Usage, Options & Common CI Errorsgit diff shows changes between commits, the index, and the working tree. Reference for --staged, --name-only,…