Home > Net >  Pre-push git hook isn't picked up
Pre-push git hook isn't picked up

Time:11-21

I'm trying to get the pre-push git hook to work. I can run it from git bash just fine, it just doesn't get picked up when I'm pushing. Am I doing something wrong?

File is ".git\hooks\pre-push"

File type is: Shell Script (.sh)

File contents:

#!/bin/sh

echo "*****Running pre-push******"

Results, when running from git bash:

$ ./pre-push.sh

*****Running pre-push******

CodePudding user response:

Two things:

  1. Make sure pre-push doesn't have an extension. The file should just be called pre-push, with no .sh at the end. Bash knows it's a shell script because of the '#!/bin/sh'.

  2. Configure the hooks path to be .git/hooks:

    git config core.hooksPath .git/hooks
    

Once you run this second step, everything should work like normal. You can also configure in globally to be .git/hooks if you'd like.

  • Related