Skip to content
Snippets Groups Projects
Commit a2e0e487 authored by Teake Nutma's avatar Teake Nutma
Browse files

Add delete-merged script

parent 044c9f23
No related merge requests found
......@@ -18,4 +18,8 @@ $ git log-mr [<revision range>]
# Lists local branches and their merge status, ordered by last commit date
$ git lastbranch [--merged <rev>]
# Deletes local branches that have been merged.
# Keeps master, develop, and the current branch by default.
$ git delete-merged [--merged <rev>] [--keep <regex of branches to keep>]
```
#!/usr/bin/env bash
#
# Deletes local branches that have been merged. Keeps master, develop and the current branch by default.
#
MERGE_TARGET='origin/develop'
KEEP='master|develop'
while :; do
case $1 in
--merged)
if [ -n "$2" ]; then
MERGE_TARGET=$2
shift
fi
;;
--keep)
if [ -n "$2" ]; then
KEEP=$2
shift
fi
;;
*)
break
esac
shift
done
current=$(git rev-parse --abbrev-ref HEAD)
git for-each-ref refs/heads/ --format='%(refname:short)' --merged "${MERGE_TARGET}" | grep -v -E "(${current}|(${KEEP}))" | xargs git branch -d
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment