git-delete-squashed

by not-an-aardvark

not-an-aardvark / git-delete-squashed

Delete branches that have been squashed and merged into master

237 Stars 16 Forks Last release: Not found MIT License 18 Commits 4 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

git-delete-squashed

This is a tool that deletes all of your git branches that have been "squash-merged" into master.

This is useful if you work on a project that squashes branches into master. After your branch is squashed and merged, you can use this tool to clean up the local branch.

Usage

sh

To run as a shellscript, simply copy the following command (setting up an alias is recommended). There's no need to clone the repo.

git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done

Node.js

You can also install the tool as a Node.js package from NPM. (The package code is in this repo.)

$ npm install --global git-delete-squashed
$ git-delete-squashed

Details

To determine if a branch is squash-merged, git-delete-squashed creates a temporary dangling squashed commit with

git commit-tree
. Then it uses
git cherry
to check if the squashed commit has already been applied to

master
. If so, it deletes the branch.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.