| Situation | What Git does | Planning use |
|---|---|---|
| Merged-in history is a descendant of the current history | With the default –ff, only the branch pointer is updated and no merge commit is created. | Expect the branch to move forward with no new commit. |
| Histories have diverged | Git creates a merge commit with two parents. | Expect a commit that names both lines of work. |
| –no-ff | Creates a merge commit in all cases, even when a fast-forward was possible. | Use it when the merge itself should be visible in history. |
| –ff-only | Refuses to merge and exits with a non-zero status when a fast-forward is not possible. | Use it where a merge commit must never appear by accident. |
| Same part of a file changed differently | The merge stops with a conflict, and git merge –abort can only be run after that point. | Resolve the conflict or abort the merge. |
| git rebase | Replays one branch’s commits on top of another and creates new commits instead of a merge commit. | Avoid it for commits already pushed to a shared branch. |
Behaviour above follows the Git manual for version 2.29.0 and, for rebase, a GitHub community discussion on rebase and merge.
How does Git merge work? It takes the changes made since two histories diverged, combines them, and records the result in a new commit with two parent commits, unless a fast-forward is possible.
This essay belongs with the other programming essays on this site. It looks at what happens to history when branches are combined, not at everyday branch commands.
What a merge changes in your history
A merge changes the branch you are standing on and leaves the others alone. The Git manual describes git merge as incorporating changes from the named commits since the time their histories diverged from the current branch. The practical consequence is that you choose which branch gains the new work, and that choice decides what the history looks like afterwards.

A GitHub community discussion calls merging non-destructive: the existing branches are not changed in any way. That property is similar in spirit to what what is a pure function describes for code, where inputs are left untouched and a new result is produced. Here the new result is a commit.

The options below decide how that result is recorded.

- Let the default run. The manual says –ff is the default, so Git fast-forwards when it can and creates a merge commit when it cannot. This suits most day-to-day merges.
- Force a merge commit with –no-ff. The manual says this creates a merge commit in all cases. Choose it when you want a permanent marker that a branch was merged.
- Refuse anything else with –ff-only. Git exits with a non-zero status when a fast-forward is not possible. This suits scripts and update routines that should never produce a merge commit.
- Inspect first with –no-commit. Git stops just before creating the merge commit so you can inspect the result. It only helps when a merge commit would actually be made.
Merge or rebase: choosing for a shared branch
Merge suits work that others already have, and rebase suits private work that has not been shared. The same discussion states the rule plainly: never rebase commits that have already been pushed to a shared branch. A merge adds a commit and rewrites nothing, so it is the safer default when other people hold copies of the history.
- Choose merge when the branches are shared, or when you want the record to show that two lines of work were joined.
- Choose rebase when the commits are only on your machine and you want them to sit on top of the latest base.
- Wait and merge instead if you are unsure whether anyone has pulled your commits. Rebasing creates new commits, which would diverge from the copies other people hold.
Fast-forward merges
A fast-forward merge moves a branch pointer and nothing else. The manual describes it as updating the branch pointer to match the merged branch, and it applies when the merged-in history is a descendant of the current history. No new commit is needed, because the current branch’s history is already contained in the other one.

The manual also notes that –ff is the default except when merging an annotated tag. If the merged-in history is not a descendant, Git falls back to creating a merge commit.
This is why git fast-forward merge output looks so quiet compared with other merges. Git has no changes to combine and nothing new to record.
Merge base and three-way merge
When histories have diverged, Git needs a reference point to tell which side changed what. That point is the merge base, the most recent common ancestor of the two branches. A Codefinity course explains that the term “three-way” refers to the three versions involved: the most recent common ancestor, the current branch’s version and the merged branch’s version.
What Git compares
Git identifies the changes made on each branch after the most recent common ancestor. The manual’s own example describes the merge as replaying the changes made on the topic branch since it diverged from master. Without the common ancestor, Git could not tell a deliberate edit from a file that simply differs.
What gets recorded
Changes that do not overlap combine automatically. The result goes into a merge commit, which, as freeCodeCamp’s merge guide puts it, has two parents: the two commits it merged. That structure is the difference between a merge and a plain commit, and it is what lets history show where lines of work joined.
Merge conflicts
A merge conflict happens when both branches change the same part of the same file differently. Graphite’s merge guide states it this way, and the Codefinity course adds the other half: changes that do not overlap merge automatically, and otherwise a conflict occurs. Git cannot choose between two edits to the same lines, so it hands the decision to you.

Git marks the affected file with conflict markers, lines that begin with <<<<<<< and >>>>>>> and surround the competing versions. Edit the file to the result you want, remove the markers and finish the merge. The merge stops until the conflict is resolved, so nothing is recorded half-finished.
Short-lived branches that touch different files conflict less often. Long-running branches that edit shared files conflict more, because the changes since the merge base pile up on both sides.
How rebase differs internally
Rebase rewrites history where merge adds to it. According to the GitHub discussion, git rebase replays the commits of one branch on top of another. Instead of creating a merge commit, Git moves the base of the feature branch.
The key internal difference is that rebasing creates brand new commits for each original commit. A merge keeps the original commits and adds one that joins them. A rebase leaves a feature branch with different commits from the ones it started with, which is why the shared-branch rule matters.
For understanding git rebase internals, the sequence is: Git takes each commit on the branch, replays it onto the new base and records it as a new commit. The result has no merge commit and no second parent. Whether that is a benefit depends on whether you prefer a record of the join or a history without one.
The default merge strategy
The strategy is the algorithm that combines the trees. The manual for version 2.29.0 says that, when no -s option is given, Git uses git merge-recursive when merging a single head and git merge-octopus otherwise. In practice, an ordinary merge of one branch into another uses merge-recursive, and merging several heads at once uses the octopus strategy.
The name merge-recursive is only a label here. For the general idea behind the word, how recursion works covers the programming concept on its own.
Frequently asked questions
Can I stop a fast-forward merge before it commits?
No. The manual explains that fast-forward updates do not create a merge commit, so –no-commit cannot stop them.
What does –squash do?
It produces the merge result without actually making a commit or moving HEAD, so you commit the combined changes yourself afterwards.
Is a fast-forward always the default?
Almost always. The manual says –ff is the default unless you merge an annotated, and possibly signed, tag, in which case merging behaves like –no-ff.
When can I run git merge –abort?
Only after a merge has resulted in conflicts, according to the manual. Before that point there is nothing to abort.



