Home·Terminal commands

git merge

git

Usage

git merge [--no-ff|--squash] <branch>

Brings the work of another branch into the current one; --squash records no merge, so git still counts that branch as unmerged afterwards.

Common flags

FlagMeaning
--no-ffalways record a merge commit, even when a fast-forward was possible
--ff-onlyrefuse unless it can fast-forward
--squashstage the combined change without committing or recording a merge
--abortundo a merge that stopped on conflicts
--continuefinish after you resolved the conflicts
-X ours|theirsauto-resolve conflicting hunks one way
--no-commitmerge but leave the commit to you

Examples

git merge --no-ff feature/login

keeps the branch visible in history

git merge --abort

gets you back to before the conflicted merge

git merge --squash feature/login

one flat change, staged; you still have to commit

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git merge do?

Brings the work of another branch into the current one; --squash records no merge, so git still counts that branch as unmerged afterwards.

Q. How do I type it?

git merge [--no-ff|--squash] <branch> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-merge