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:

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:

  1. Navigate to your repository on GitHub
  2. Click Settings in the top menu
  3. Scroll down to the Pull Requests section
  4. Uncheck “Allow merge commits”
  5. Uncheck “Allow rebase merging” (optional, but recommended)
  6. Check “Allow squash merging”

Now your collaborators will only be able to squash merge their PRs.