# vim: ft=sh: # Automatic branch merger (merge branch, push it to server and remove branch) # Expects name of the branch as argument # It fails if it's not fast forward merge and if there is fixup! commit. gitbmerge() { ( set -e if [ -n "$(git log --grep="^fixup\!" HEAD.."$1")" ]; then echo "First squash fixups!" exit 1 fi local WT="$(git worktree list | sed -nE "/\[$1\]/{s/([^ ]+) .*/\1/p}")" if [ -n "$WT" ]; then rm -r "$WT" git worktree prune fi git merge --ff-only "$1" && git push && git branch -d "$1" && git push origin :"$1" ) } # Create new branch from HEAD gitbnew() { git branch "$1" HEAD local NW="$(git rev-parse --show-toplevel)-$1" git worktree add "$NW" $1 cd "$NW" git submodule update --init --recursive }