Ignoring Git Hooks When RebasingFebruary 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
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.
#!/bin/sh BRANCH_NAME=$(git branch | grep '*' | sed 's/* //') if [ $BRANCH_NAME != '(no branch)' ] then # your regularly scheduled hook fi
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.