From 99f2dae3a5c15c62f1d22e9b208377c05cff5761 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Fri, 25 Mar 2022 21:43:07 +0100 Subject: [PATCH] Add git cleanup alias --- home/.config/git/config | 1 + 1 file changed, 1 insertion(+) diff --git a/home/.config/git/config b/home/.config/git/config index 8a3ea5b..0e2108d 100644 --- a/home/.config/git/config +++ b/home/.config/git/config @@ -6,6 +6,7 @@ quickclone = "clone --single-branch --depth=1" bareclone = "!sh -c 'git clone --bare \"$0\" \"$1\"/.bare; echo \"gitdir: ./.bare\" > \"$1/.git\"'" bareinit = "!sh -c 'git init --bare \"$0\"/.bare; echo \"gitdir: ./.bare\" > \"$0/.git\"'" + cleanup = "!default_branch=$(git remote show origin | awk '/HEAD branch/ {print $NF}'); git remote prune origin && git checkout -q $default_branch && git for-each-ref refs/heads/ '--format=%(refname:short)' | while read branch; do mergeBase=$(git merge-base $default_branch $branch) && [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == '-'* ]] && git branch -D $branch; done" m = "merge" p = "push"