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
| Flag | Meaning |
|---|---|
| --no-ff | always record a merge commit, even when a fast-forward was possible |
| --ff-only | refuse unless it can fast-forward |
| --squash | stage the combined change without committing or recording a merge |
| --abort | undo a merge that stopped on conflicts |
| --continue | finish after you resolved the conflicts |
| -X ours|theirs | auto-resolve conflicting hunks one way |
| --no-commit | merge but leave the commit to you |
Examples
git merge --no-ff feature/loginkeeps the branch visible in history
git merge --abortgets you back to before the conflicted merge
git merge --squash feature/loginone 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