My git workflow includes the hack and ship commands for easy tracking of a shared master branch, and conveniently delivering commits. Feature branches are cheap and fast in git, and I am often spawning new branches to try stuff out or work on unrelated things.

Now, meet chop - for chopping down the current working branch after it has been shipped and is no longer needed. The script changes the current branch to master, and then deletes the branch you was previously on. If you give a branch-name as an argument that will be the new current branch.

#!/bin/sh -x
set -o errexit
CURRENT_BRANCH=$(git branch | grep '\*')
git checkout ${1:-"master"} || exit 1
git branch -d ${CURRENT_BRANCH:2}

I use this small script is multiple times every day, and I really like the name of it. There is not a whole lot of functionlity, but as this is an often repeated action, it makes sense to automate it.

Enjoy!