Overview

The way you integrate a branch decides the shape of history: a merge commit, a straight line, or one squashed commit. Choose before merging, because changing it later rewrites shared history. For daily commands see git-commands; for rebase recipes see git-rebase.

Integration styles

Choose the style from your branch policy: linear history, merge commits, or one commit per PR.

CommandResulting historyUse when
git merge featureFast-forward if possible, else a merge commit.The default; fine for most flows.
git merge --ff-only featureLinear; fails if a fast-forward is impossible.Enforcing “rebase before merge”.
git merge --no-ff featureAlways a merge commit.The branch boundary matters for audit or revert.
git merge --squash feature, then git commitOne commit; no parent link to the branch.One reviewable commit per PR (GitHub “Squash and merge”).
git rebase main, then git merge --ff-onlyLinear; the branch’s SHAs change.Clean history for local, not-yet-pushed work.

Ours and theirs

The sides swap between commands.

Contextourstheirs
git merge featureCurrent branch (HEAD).feature.
git rebase mainmain, the new base.Your commit being replayed.
git cherry-pick <ref>Current branch (HEAD).The picked commit.
CommandEffect
git checkout --ours <file> / --theirs <file>Take one side of a conflicted file.
git merge -X ours / -X theirsPrefer one side only for conflicting hunks; other changes still merge.
git merge -s oursRecord a merge but keep the current tree; the other branch’s changes are discarded.

Strategies (-s)

Leave the strategy at its default unless you need ours, subtree, or octopus.

StrategyNotes
ortDefault for a two-head merge; handles renames. recursive is now a synonym.
resolveTwo-head three-way merge; does not handle renames.
octopusDefault for three or more heads; refuses merges that need manual resolution.
oursKeeps the current tree whatever the other heads contain.
subtreeort adjusted for merging a project into a subdirectory.

Gotchas

Avoid these; each leaves a branch undeleted, drops changes, or creates stray merge commits.

GotchaFix
git branch -d fails after a squash merge; git cannot see it as merged.Confirm the squash landed, then git branch -D.
-s ours and -X ours look alike but differ.-s drops the other side entirely; -X only resolves conflicts.
A merge without --ff-only can create merge commits you did not intend.git config --global merge.ff only or pull.ff only.
Rebasing pushed commits breaks teammates’ clones.Rebase before the first push; afterwards merge.
-X theirs hides real conflicts.Resolve by hand when the conflict is semantic.