branching

git merge

Joins the history of another branch into the current one, creating a merge commit when histories diverge. Preserves the full branching topology.

git merge [<options>] [<commit>...]

Common flags

Flag Purpose
--no-ff Always create a merge commit even if fast-forward is possible
--ff-only Refuse the merge unless it's a clean fast-forward
--squash Combine changes into a single commit on the current branch
--abort Cancel an in-progress conflicted merge
--continue Resume after resolving conflicts
-s <strategy> Choose merge strategy (ort, recursive, ours, etc.)

Examples

git merge feature/login

Merge the feature branch into the current one

git merge --no-ff release/1.2

Preserve branch topology with an explicit merge commit

git merge --abort

Bail out of a conflicted merge and restore pre-merge state

Gotcha

After resolving conflicts, you must 'git add' the fixed files and 'git commit' (or 'git merge --continue') — running the wrong command can leave the merge half-finished.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge