I’ll introduce a command to bulk delete merged remote branches in Git.
Bulk Delete Command for Merged Remote Branches
git branch --remote --merged master | \\
grep -v -e master -e release -e staging | \\
sed -e 's% *origin/%%' | \\
xargs -I% git push --delete origin %
This assumes that master, release, and staging branches are excluded from deletion.
Synchronizing Remote Branches After Deletion
Even if someone else deletes remote branches, the remote branch information remains in your local branches.
You can synchronize remote branch information with the following command:
git remote prune origin
Alternatively, you can synchronize by adding the —prune option like:
git fetch --prune
or
git pull --prune
Reference Information
- github - How can I delete all git branches which have been merged? - Stack Overflow
- Bulk Delete Merged Remote Branches in Git - Qiita (Gitでリモートのマージ済みのブランチを一括削除する - Qiita)
- How to Delete Remote Branches in Git · DQNEO Startup Diary (Gitで、リモートにあるブランチを削除する方法 · DQNEO起業日記)
- Cleaning Up Unused Remote Branches in Git - Qiita (Gitで使われていないリモートブランチの整理 - Qiita)
That’s all from the Gemba.
