aboutsummaryrefslogtreecommitdiff
path: root/bin/git-cleanup
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-13 09:34:32 -0300
committerEuAndreh <eu@euandre.org>2022-08-13 09:34:32 -0300
commit68f724fb62520a75c536bd15dc10ea8ca0811680 (patch)
treef395586c480ddb7664bb9e4a31f64416391c4654 /bin/git-cleanup
parentbin/forever: Add working utility (diff)
downloaddotfiles-68f724fb62520a75c536bd15dc10ea8ca0811680.tar.gz
dotfiles-68f724fb62520a75c536bd15dc10ea8ca0811680.tar.xz
bin/git-cleanup: Add working utility
Diffstat (limited to 'bin/git-cleanup')
-rwxr-xr-xbin/git-cleanup74
1 files changed, 74 insertions, 0 deletions
diff --git a/bin/git-cleanup b/bin/git-cleanup
new file mode 100755
index 0000000..4196cff
--- /dev/null
+++ b/bin/git-cleanup
@@ -0,0 +1,74 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ git cleanup [REMOTE]
+ git cleanup -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ REMOTE the remote to prune the remote tracking
+ branches from (default: origin)
+
+
+ Delete merged branches, both local and remote-tracking.
+
+
+ Examples:
+
+ Cleanup branches from "origin":
+
+ $ git cleanup
+
+
+ Delete branches from "upstream":
+
+ $ git cleanup upstream
+ EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+REMOTE="${1:-origin}"
+
+git branch --merged |
+ grep -v -e '^\*' -e '^. main$' |
+ xargs git branch -d
+
+git remote prune "$REMOTE"