doc/user/project/merge_requests/squash_and_merge.md
{{< details >}}
{{< /details >}}
Squash and merge combines multiple small commits into a single meaningful commit. This strategy keeps your repository history clean and makes it easier to track or revert changes. When you work on multiple features at once, squashing separates each feature's changes into distinct, logical units.
Each time a branch merges into your base branch, up to two commits are added:
By default, squashed commits contain the following metadata:
Project owners can create new default messages for all squash commits and merge commits.
Users with permission to create or edit a merge request can set the default squash options for a merge request.
Prerequisites:
To do this:
If your project allows you to select squashing options for merge requests, to squash the commits as part of the merge process:
Prerequisites:
To configure the default squashing behavior for all merge requests in your project:
You should not squash and merge long-running branches. Instead, use a merge method that preserves the original commit history, such as merge commits or fast-forward merges.
When you squash and merge a branch that continues to receive new commits, the branch history diverges from the target branch. Squashing creates a single new commit on the target branch with a different SHA. If you continue working on the source branch without rebasing or merging the target branch back in, Git treats the histories as diverged.
When you open a new merge request from that source branch, you see the following:
The diff correctly shows only the new changes not yet in the target branch.
To keep a long-running branch in sync with its target after a squash merge: