Created
June 6, 2017 15:54
-
-
Save nickolasburr/c7398d8f4d12ed1f5f7af3f314780ab8 to your computer and use it in GitHub Desktop.
clip: Delete local branch, with option to force delete unmerged branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# clip: Delete local branch, with option to force delete unmerged branches | |
clip () { | |
# return if we're not inside an actual work tree | |
if [[ ! "$(git rev-parse --is-inside-work-tree)" ]] 2>/dev/null; then | |
echo "fatal: Not a git repository (or any of the parent directories): .git" | |
return 1 | |
fi | |
# if no arguments were given to `clip`, notify the user and return | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: clip [-f|--force] BRANCHREF" | |
return 1 | |
fi | |
# wrangle the given flag options | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-f|--force) | |
shift | |
git branch -D "$1" | |
break | |
;; | |
*) | |
git branch -d "$1" | |
break | |
;; | |
esac | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment