morristech
5/10/2018 - 9:08 AM

Merge all your branches into a hacking branch.

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"