Initial commit of git branch cleaner
This commit is contained in:
parent
862beadfdc
commit
f61d8e0846
1 changed files with 31 additions and 0 deletions
31
git_tidy_local_branches.sh
Executable file
31
git_tidy_local_branches.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# first we prune origin to ensure our local list of remote branches is up to date
|
||||||
|
git remote prune origin
|
||||||
|
|
||||||
|
GONE_BRANCHES=$(git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}')
|
||||||
|
echo "[DEBUG]: $GONE_BRANCHES"
|
||||||
|
|
||||||
|
if [ -z "$GONE_BRANCHES" ]; then
|
||||||
|
echo "Could not find any local branches where the remote is gone"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "-f" ]; then
|
||||||
|
echo "$GONE_BRANCHES" | xargs git branch -D
|
||||||
|
#TODO: Do this in a loop so that we can provide output on which branches failed to delete
|
||||||
|
else
|
||||||
|
echo "$GONE_BRANCHES" | xargs git branch -d
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
FAILED_TO_DELETE="true"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$FAILED_TO_DELETE" = "true" ]; then
|
||||||
|
# echo "error: Some local branches are not fully merged."
|
||||||
|
echo
|
||||||
|
echo "If you are sure you want to delete all branches above, run 'git-glean -f'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Handy script when following GitFlow and rebasing, since `git branch --merged master` will never list
|
||||||
|
# a rebased but merged branch (as their commit history differs).
|
||||||
Loading…
Add table
Add a link
Reference in a new issue