Garrett Murphey

Ruby & JavaScript Development

Ignoring Git Hooks When Rebasing

February 02, 2013

If you’re in the habit of running git rebase before pushing to origin (and you should be, in my opinion), you may notice some annoying things happening if you have prepare-commit-msg and pre-commit hooks enabled for your repository. I have both – one to pre-prend the branch name on my commit messages and another to run build processes. When I would clean up my commits with an interactive rebase each of the commits in the rebase would have their messages edited and a build would be made for every step of the way. That finally annoyed me enough to add a simple condition to my hooks.

BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')

if [ $BRANCH_NAME != '(no branch)' ]
  # your regularly scheduled hook

Now those commits won’t run when rebasing (rebase runs in a headless branch) and you could technically run a separate hook just for rebases.

Other Recent Posts