In Bitbucket Cloud, how do the six pull request merge strategies differ in the history they leave on the destination branch?
answer
- merge commit or not
- keep commits or fold them
- replay versus move the pointer
- the fast-forward-only variants refuse
- project default, repository inherits
basics
~20 sBitbucket Cloud offers Merge commit, Fast forward, Rebase, merge, Rebase, fast-forward, Squash and Squash, fast-forward only. They differ in whether a merge commit is added, whether source commits stay separate or are combined, and whether an out-of-date branch is refused.
solid answer
~40 s**Merge commit** (`git merge --no-ff`) keeps every source commit and adds a merge commit. **Fast forward** (`--ff-only`) just moves the destination to the source's commits and only works when the destination has no new commits. **Rebase, merge** replays each source commit onto the destination as a new commit, then adds a merge commit; **Rebase, fast-forward** replays them and fast-forwards, leaving a linear history with no merge commit. **Squash** (`--squash`) folds the branch into one new commit; **Squash, fast-forward only** does the same but rejects the merge if the source branch is out of date. Neither rebase strategy modifies the pull request's own branch. The repository's default strategy decides which one the merge dialog pre-selects, and a project can set that default for its repositories.
go deeper
Recall the six strategy names and which ones add a merge commit.
Explain how the rebase variants differ from Merge commit and Fast forward, and what the fast-forward-only squash does with an out-of-date branch.
Pick a strategy for a stated history policy, and know that a repository added to a project must be switched to inherit the project's default.
Weigh bisectable per-commit history against one-commit-per-pull-request history, and decide whether one default should hold across every project.
## The six strategies When a pull request is merged in Bitbucket Cloud, the person merging picks a **merge strategy** from a dropdown in the merge dialog. The strategy decides what the destination branch's history looks like afterwards. Atlassian maps each one to a Git command: | Strategy | Git equivalent | Merge commit added? | Source commits on destination | If destination has moved on | |---|---|---|---|---| | **Merge commit** | `git merge --no-ff` | Yes | All kept, original commits | Merges anyway | | **Fast forward** | `git merge --ff-only` | No | All kept, original commits | Only possible when the destination has no new commits | | **Rebase, merge** | rebase, then `merge --no-ff` | Yes | Replayed as new non-merge commits | Replays on top, then merges | | **Rebase, fast-forward** | rebase, then `merge --ff-only` | No | Replayed as new non-merge commits | Replays on top, then fast-forwards | | **Squash** | `git merge --squash` | No | Combined into one new commit | Squashes anyway | | **Squash, fast-forward only** | `--squash --ff-only` | No | Combined into one new commit | Rejects the merge | Two facts in the table cause most confusion: - **Rebase strategies create new commits.** Replaying a commit onto a different parent produces a different commit ID, so the destination does not contain the exact commits a reviewer saw on the branch, even though the changes are the same. Bitbucket does not modify the pull request's own branch while doing this. - **"Fast-forward only" means refuse rather than adapt.** *Squash, fast-forward only* will not squash a source branch that is behind the target; the author has to bring the branch up to date first. ## Linear history and what it costs A **linear history** — no merge commits — comes from four of the six: **Fast forward**, **Rebase, fast-forward** and the two squash strategies. They differ in granularity: - **Rebase, fast-forward** keeps every commit from the branch, which suits teams that write small, meaningful commits and want `git bisect` to land on them. - **Squash** and **Squash, fast-forward only** leave one commit per pull request, which suits branches full of "fix typo" commits. - **Fast forward** keeps the original commits untouched but is only possible when nobody has merged in the meantime, so on a busy branch it often cannot be used. **Merge commit** and **Rebase, merge** keep a merge commit per pull request, which marks where each pull request landed at the cost of a branching graph. ## Squash and the pull request record Bitbucket decides that a pull request is merged by looking at the commit graph. That has a practical consequence: 1. If someone runs `git merge --squash` locally and pushes the result, the new commit has no link to the branch's commits. 2. Bitbucket therefore cannot see that the pull request was merged, and it stays **open**. 3. Its diff becomes empty because the destination already holds the same changes, but the individual commits remain visible on the pull request. Squashing through the merge dialog avoids this, because Bitbucket performs the merge and records it. After a merge through the dialog, Bitbucket also marks as merged any other open pull request made only of commits from the merged branch, such as a branch cut from it with no commits of its own. ## Setting the default - A **repository** admin chooses a **Default merge strategy**, which is the one the merge dialog shows first. - A **project** admin can set a default merge strategy at project level; repositories created in the project pick it up. - A repository **added** to an existing project does not change automatically: someone has to open that repository and switch it to **inherit** the project's settings. ## Choosing one - Want each pull request visible as a unit in history: **Merge commit**. - Want linear history with every reviewed commit: **Rebase, fast-forward**. - Want one commit per pull request: **Squash**, or **Squash, fast-forward only** if the branch must be current with the target first. Git's own merge, rebase and squash mechanics belong to the material on Git branching; here the point is which button produces which history.
- Someone ran git merge --squash locally and pushed main. Why does the Bitbucket Cloud pull request stay open?Bitbucket detects merged pull requests from the commit graph. A local squash creates a new commit with no link to the branch's commits, so Bitbucket cannot tell the pull request was merged. It stays open with an empty diff; squash through the merge dialog instead so Bitbucket records the merge.
- In Bitbucket Cloud, which strategy gives a linear main that still contains every reviewed commit separately?Rebase, fast-forward. It replays each source commit onto the destination as a new non-merge commit and fast-forwards, so there is no merge commit and no squashing. The replayed commits get new IDs, but each one still appears on main.
- Fast forward rewrites the source commits on top of the destination branch.
- Rebase, merge rewrites the pull request's source branch in place.
- Squash, fast-forward only rebases an out-of-date branch automatically before squashing.
- Pushing a local git merge --squash result closes the pull request automatically.
- Rebase, fast-forward keeps the original commit IDs from the source branch.