Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
executable file 32 lines (26 sloc) 864 Bytes
#!/usr/bin/env bash
# git-dwtb: "done with this branch":
# * check back out to master
# * pull "${REMOTE}"/master
# * delete the original branch
# * prune "${REMOTE}"
set -eo pipefail
function __git_find_main_branch() {
mapfile -t branches < <(git branch --format='%(refname:short)')
for branch in "${branches[@]}"; do
[[ "${branch}" == "main" || "${branch}" == "master" ]] \
&& echo -n "${branch}" \
&& return
done
}
remote="${REMOTE:-origin}"
branchname=$(git rev-parse --abbrev-ref HEAD)
destination=$(__git_find_main_branch)
if [[ "${branchname}" == "${destination}" || "${branchname}" == "HEAD" ]]; then
>&2 echo "Don't run me on ${destination} or a symbolic ref!"
exit 1
fi
git checkout "${destination}" && \
git pull "${remote}" "${destination}" && \
git branch -D "${branchname}" && \
git remote prune "${remote}"