Question
How to squash all merges that only merged a single commit (due to git pull)?
In a git repository with several contributors, there are a lot of commits titled Merge branch 'main' of <repository url>
. These create unnecessary clutter when looking through a git log. Most of them are created by one person doing work on a branch while another person has pushed to the same branch in the meantime. The first person commits then pulls, creating the merge commit.
We could try and require everyone to use git pull --rebase
, but that wouldn't affect past commits and would make it harder for some of the contributors who are newer to Git. All these merges have only one commit of divergence before them, so they are straightforward to take care of manually using git rebase -i
, but that's a lot of work. Is there a way to remove all these merges (squashing them into the previous commit) without having to manually squash them one by one?