Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pre-push git hook isn't picked up

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

File contents:

#!/bin/sh

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

Results, when running from git bash:

$ ./pre-push.sh

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading