Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active October 31, 2018 16:18
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 JoshCheek/fee11883a8cdc6697eb3478fd9e03602 to your computer and use it in GitHub Desktop.
Save JoshCheek/fee11883a8cdc6697eb3478fd9e03602 to your computer and use it in GitHub Desktop.
git-nuke: Delete remote and local branch
#!/usr/bin/env bash
# a variation on https://twitter.com/r00k/status/1057657001013100544
function git-nuke() {
local local_branch="$1"
local upstream="$(git rev-parse --abbrev-ref "$local_branch"'@{upstream}')"
if [[ -n "$upstream" ]]; then
IFS=/ read remote_repo remote_branch <<<"$upstream"
git push "$remote_repo" --delete "$remote_branch" && git branch -D "$local_branch"
else
exit 1
fi
}
git-nuke "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment