2025-05-11

Cleaning Branches After Squash and Merge

Programming
Notes
This article was translated by GPT-5.2-Codex. The original is here.

Introduction

When you merge branches on GitHub, there are three options.

  • Create a merge commit
  • Rebase and merge
  • Squash and merge

At work I often use Create a merge commit, but in personal projects I sometimes use Squash and merge to avoid keeping small fix commits on master, since the problems that arise are usually less troublesome.

For the common issues with Squash and merge, please refer to articles you can find by searching.

The conflict issue after squash merge can apparently be solved with a rebase option.

However, when deleting merged branches, you must use -D instead of -d. I regularly run git pull --prune to clean up merged local branches, so it is inconvenient that I can't delete them with a single command.

For --no-ff

When using Create a merge commit, I set the following alias in ~/.config/git/config and delete merged branches with git delete-merged-branch.

I modified this alias based on the following articles to protect develop, main, and master.

But with this, branches merged with Squash and merge are not removed.

Want to support Squash and merge

When I searched, I found four methods.

The first is poi, developed as a gh extension. The second and third are Node packages that can be run with npx. The fourth is a shell-script implementation of git-delete-squashed.

gh-poi

I decided to try poi. First, log in with gh.

If you haven't used the gh command, install it by following Installation.

After logging in, install gh-poi.

When I ran gh poi to delete squash-merged branches, I got the following.

It did delete squash-merged branches. Unlike git-delete-squashed, it seems to determine whether a branch is squash-merged based on GitHub PR information.

Fetching data from GitHub might not be ideal, but I'll try it for a while. If I run into problems, I may also try git-delete-squashed.

【改訂新版】Gitポケットリファレンス

【改訂新版】Gitポケットリファレンス

Amazon アソシエイトについて

この記事には Amazon アソシエイトのリンクが含まれています。Amazonのアソシエイトとして、SuzumiyaAoba は適格販売により収入を得ています。