Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save meatballhat/1d3a6196c8614cb9ec7d75af7d134281 to your computer and use it in GitHub Desktop.
Save meatballhat/1d3a6196c8614cb9ec7d75af7d134281 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
: ${GIT:=git}
__mainremote() {
if [[ "${REMOTE}" ]] ; then
echo "${REMOTE}"
return
fi
${GIT} config --local repo.mainremote 2>/dev/null || echo origin
}
__mainbranch() {
if [[ "${BRANCH}" ]] ; then
echo "${BRANCH}"
return
fi
${GIT} config --local repo.mainbranch 2>/dev/null || echo master
}
__delbranch() {
if [[ "${1}" ]] ; then
echo "${1}"
return
fi
${GIT} rev-parse --abbrev-ref HEAD
}
main() {
local delbranch="$(__delbranch "${1}")"
${GIT} checkout "$(__mainbranch)"
${GIT} pull
${GIT} remote prune "$(__mainremote)"
if [[ $delbranch ]] ; then
${GIT} branch -d "${delbranch}"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment