bin/git-delete-remote-branch
#!/usr/bin/env bash
#
# Delete a remote git branch
#
# Copyright 2022, Joe Block <jpb@unixorn.net>
set -o pipefail
if [[ -n "$DEBUG" ]]; then
set -x
fi
function debug() {
if [[ -n "$DEBUG" ]]; then
echo "$@"
fi
}
function fail() {
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}
function has() {
# Check if a command is in $PATH
which "$@" > /dev/null 2>&1
}
if ! has git; then
fail "Can't find git in your PATH"
fi
if [[ $# -ne 2 ]]; then
myname=$(basename "$0")
fail "Usage: $myname REMOTE_NAME BRANCH_NAME"
fi
REMOTE="$1"
BRANCH_NAME="$2"
exec git push "$REMOTE" --delete "$BRANCH_NAME"