I've looked at the githooks manpage but unless I'm missing something I don't see an option for local, post-push git hooks. I'd like to have one that updates the api docs on my web server (for which I already have a script) after I push the master branch to the GitHub repo. Of course I could just write my own script that combines the git push and the api docs run, but that feels somewhat inelegant.
No. Hooks are per-repository and are never pushed.
The pre-receive hook is executed every time somebody uses git push to push commits to the repository. It should always reside in the remote repository that is the destination of the push, not in the originating repository.
If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook.
Another solution to this problem is to have a wrapper for git push
that executes .git/hooks/pre-push
and .git/hooks/post-push
scripts before and after the git push
call. A possible wrapper could look like this:
#!/bin/sh GIT_DIR_="$(git rev-parse --git-dir)" BRANCH="$(git rev-parse --symbolic --abbrev-ref $(git symbolic-ref HEAD))" PRE_PUSH="$GIT_DIR_/hooks/pre-push" POST_PUSH="$GIT_DIR_/hooks/post-push" test -x "$PRE_PUSH" && exec "$PRE_PUSH" "$BRANCH" "$@" git push "$@" test $? -eq 0 && test -x "$POST_PUSH" && exec "$POST_PUSH" "$BRANCH" "$@"
Saved as git-push-wh
somewhere in your PATH
, it can then be called as git push-wh
if you want to push with hooks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With