Notes
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.
- I stopped using squash merge in Git - Mobile Factory Tech Blog
- Graduating from squash merge and moving to a branch strategy that accelerates product development | SocialDog Tech Blog
The conflict issue after squash merge can apparently be solved with a rebase option.
- Resolve conflicts for branches containing squash-merged commits in Git #onto - Qiita
- When Cascading PRs conflict in a squash merge environment - oinume journal
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.
- seachicken/gh-poi: ✨ Safely clean up your local branches
- not-an-aardvark/git-delete-squashed: Delete branches that have been squashed and merged into main
- teppeis/git-delete-squashed: Delete branches that have been squashed and merged into master
- Delete branches squashed on GitHub · ryym.log
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.
