Skip to content

Instantly share code, notes, and snippets.

@newfurniturey
Created July 23, 2017 12:49
Show Gist options
  • Save newfurniturey/e570fd48f11d61773ceed178cbd4eec4 to your computer and use it in GitHub Desktop.
Save newfurniturey/e570fd48f11d61773ceed178cbd4eec4 to your computer and use it in GitHub Desktop.
Simple local/remote git branch deletion alias
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