Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Created August 7, 2014 05:49
Show Gist options
  • Save JakeWharton/bb4f0daa50c9359f5683 to your computer and use it in GitHub Desktop.
Save JakeWharton/bb4f0daa50c9359f5683 to your computer and use it in GitHub Desktop.
Merge all your branches into a hacking branch.
function hackhackhack() {
# Merge all your local branches into a hacking branch.
PREFIX="$(whoami)/"
git co master
git branch -D "${PREFIX}hackhackhack"
git pull --prune
git co -b "${PREFIX}hackhackhack"
for branch in $(git branch | \grep "$PREFIX"); do
git merge --no-edit $branch
done
}

HackHackHack

When I'm (binge) working on open source projects I frequently get 4 or more branches with changes going at once. While these chages are independent and atomic, I often want to continue development on top of all of these changes together.

Previously I would just manually merge these into a hack branch. Every time a PR would be merged I'd have to re-create my hack branch with the latest from upstream master and the unmerged branches.

I grew tired of this.

hackhackhack is a Bash function which merges all your local branches into a hacking branch automatically. When used with something that kill merged branches automatically[1] this speeds up my iteration.

In order to use this you need to prefix your branches with your computer username and a "/" (e.g., jw/).

[1]: alias rm-merged-local="git fetch --prune && git branch --merged master | \grep -v 'master' | xargs git branch -D"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment