Keep Your Git History Clean: Configure GitHub for Squash-Only Merges
If you’ve ever scrolled through a repository’s commit history only to find dozens of “merge branch” commits, there’s a simple solution: configure your GitHub repository to enforce squash merging.
Why squash merging?
When you squash merge a pull request, GitHub combines all the PR’s commits into a single, cohesive commit on your main branch. This approach offers several benefits:
- Cleaner history: Your main branch shows one commit per feature or fix, making it easy to understand what changed and when
- Easier reversions: Rolling back a feature means reverting a single commit instead of tracking down multiple related commits
- Better release notes: Each commit represents a complete unit of work, making changelog generation straightforward
With squash merging, every PR becomes an atomic unit. One feature, one commit, one-click revert. Need to bring it back later? Just revert the revert.
How to configure your repository
In your repository settings:
- Navigate to your repository on GitHub
- Click Settings in the top menu
- Scroll down to the Pull Requests section
- Uncheck “Allow merge commits”
- Uncheck “Allow rebase merging” (optional, but recommended)
- Check “Allow squash merging”
Now your collaborators will only be able to squash merge their PRs.