Skip to content

Instantly share code, notes, and snippets.

@mauriciogior
Created January 24, 2019 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciogior/55b86fe5feda3bf0170ace65b65c8610 to your computer and use it in GitHub Desktop.
Save mauriciogior/55b86fe5feda3bf0170ace65b65c8610 to your computer and use it in GitHub Desktop.
git-delete-branch
#!/usr/bin/env bash
# reset environment variables that could interfere with normal usage
export GREP_OPTIONS=
# put all utility functions here
# make a temporary file
git_extra_mktemp() {
mktemp -t "$(basename "$0")".XXX
}
#
# check whether current directory is inside a git repository
#
is_git_repo() {
git rev-parse --show-toplevel > /dev/null 2>&1
result=$?
if test $result != 0; then
>&2 echo 'Not a git repo!'
exit $result
fi
}
is_git_repo
# Assert there is at least one branch provided
test -z $1 && echo "branch required." 1>&2 && exit 1
for branch in "$@"
do
remote=$(git config branch.$branch.remote)
test -z $remote && remote="origin"
ref=$(git config branch.$branch.merge)
test -z $ref && ref="refs/heads/$branch"
git branch -D $branch
git branch -d -r $remote/$branch
git push $remote :$ref
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment