Created
July 23, 2017 12:49
-
-
Save newfurniturey/e570fd48f11d61773ceed178cbd4eec4 to your computer and use it in GitHub Desktop.
Simple local/remote git branch deletion alias
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
git-delete-func() { | |
# do basic pattern matching to prevent command injection (or mistakes)... | |
# note: this pattern is just a character-set based on my standard branches - it could be better =P | |
pattern="a-zA-Z0-9/._-" | |
if [[ $1 =~ [^$pattern] ]]; then | |
echo -e "invalid branch pattern\n"; | |
return 1; | |
fi; | |
# verify the branch exists | |
if [ -z "`git show-ref refs/heads/$1`" ]; then | |
echo -e "branch not found =[\n"; | |
return 1; | |
fi; | |
# deletes | |
git branch -D $1; | |
git push origin --delete $1; | |
return 0; | |
} | |
alias git-delete=git-delete-func; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment