2019-06-09 18:25:13 -04:00
---
2020-07-28 14:09:36 -04:00
stage: Create
group: Source Code
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-06-09 18:25:13 -04:00
---
2021-02-09 13:09:59 -05:00
# Squash and merge **(FREE)**
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
As you work on a feature branch, you often create small, self-contained commits. These small commits
help describe the process of building a feature, but can clutter your Git history after the feature
is finished. As you finish features, you can combine these commits and ensure a cleaner merge history
in your Git repository by using the _squash and merge_ strategy.
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
- Small commits are joined together, making it simpler to [revert all parts of a change ](revert_changes.md ).
- When the single commit merges into the target branch, it retains the full commit history.
- Your base branch remains clean, and contains meaningful commit messages.
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
Each time a branch merges into your base branch, up to two commits are added:
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
- The single commit created by squashing the commits from the branch.
- A merge commit, unless you have [enabled fast-forward merges ](fast_forward_merge.md#enabling-fast-forward-merges )
in your project. Fast-forward merges disable both merge commits and squashing.
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
By default, squashed commits contain the following metadata:
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
- Message: Description of the squash commit, or a customized message
- Author: User that created the merge request
- Committer: User who initiated the squash
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
Project owners can [create new default messages ](commit_templates.md ) for all
squash commits and merge commits.
2020-08-11 20:09:52 -04:00
2022-01-05 13:13:30 -05:00
## Set default squash options for a merge request
2019-02-06 07:33:11 -05:00
2022-01-05 13:13:30 -05:00
Users with permission to create or edit a merge request can set the default squash options
for a merge request. To do this:
2019-02-07 10:14:56 -05:00
2022-01-05 13:13:30 -05:00
1. Go to the merge request and select **Edit** .
1. Select or clear the **Squash commits when merge request is accepted** checkbox.
1. Select **Save changes** .
2019-02-07 10:14:56 -05:00
2022-01-05 13:13:30 -05:00
## Squash commits in a merge request
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
If your project allows you to select squashing options for merge requests, to
squash the commits as part of the merge process:
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
1. Go to the merge request, and scroll to the merge request reports section that
contains the **Merge** button.
1. Ensure the **Squash commits** checkbox is selected. This checkbox doesn't display
if the project's squashing option is set to either **Do not allow** or **Require** .
1. Optional. To modify either the squash commit message or the merge commit message
(depending on your project configuration), select **Modify commit messages** .
1. When the merge request is ready to merge, select **Merge** .
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
## Configure squash options for a project
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/17613) in GitLab 13.2 [with a flag](../../../administration/feature_flags.md) named `squash_options`, disabled by default.
> - [Enabled on GitLab.com and self-managed by default](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39382) in GitLab 13.3.
> - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/232536) in GitLab 13.8. Feature flag `squash_options` removed.
2019-07-02 20:42:38 -04:00
2022-01-05 13:13:30 -05:00
To configure the default squashing behavior for all merge requests in your project:
2018-05-29 05:51:43 -04:00
2022-01-05 13:13:30 -05:00
1. On the top bar, select **Menu > Projects** and find your project.
1. On the left sidebar, select **Settings > General** .
1. Expand **Merge requests** .
1. In the **Squash commits when merging** section, select your desired behavior:
- **Do not allow**: Squashing is never performed, and the option is not displayed.
2022-03-06 16:17:22 -05:00
- **Allow**: Squashing is allowed, but cleared by default.
2022-01-05 13:13:30 -05:00
- **Encourage**: Squashing is allowed and selected by default, but can be disabled.
- **Require**: Squashing is always performed. While merge requests display the option
to squash, users cannot change it.
1. Select **Save changes** .
2020-07-03 11:09:13 -04:00
2021-12-02 13:11:52 -05:00
## Related topics
2022-01-05 13:13:30 -05:00
- [Commit message templates ](commit_templates.md )
- [Fast-forward merges ](fast_forward_merge.md )
2021-12-02 13:11:52 -05:00
2019-06-09 18:25:13 -04:00
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X` .
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->