Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
32 lines (26 sloc)
864 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |