Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git skip post-commit hook

Tags:

git

I have a git post-commit hook in my repo. I want to skip running this hook sometimes.

To skip pre-commit hook, I know I can use the --no-verify flag while commiting like this

git commit -m "message" --no-verify

But this is not skipping post-commit hook.

Is it possible to skip post-commit hook? If so how to do it?

like image 303
Sreeram TP Avatar asked Jul 16 '26 02:07

Sreeram TP


2 Answers

From the documentation:

-n --no-verify This option bypasses the pre-commit and commit-msg hooks. See also githooks[5].

so this flag does not skip the post-commit hook. There doesn't seem to be a simple, clean way to skip this flag. For a one-shot operation; you could just disable the hook and enable it again after your commit:

chmod -x .git/hooks/post-commit # disable hook
git commit ... # create commit without the post-commit hook
chmod +x .git/hooks/post-commit # re-enable hook
like image 156
Chris Maes Avatar answered Jul 18 '26 17:07

Chris Maes


It is possible. Here is what I would do for Linux and bash:

#!/bin/bash

# parse the command line of the parent process
# (assuming git only invokes the hook directly; are there any other scenarios possible?)

while IFS= read -r -d $'\0' ARG; do
    if [[ "$ARG" == '--no-verify' ]]; then
        exit 0
    fi
done < /proc/$PPID/cmdline

# or check for the git config key that suppresses the hook
# configs may be supplied directly before the subcommand temporarily (or set permanently in .git/config)
# so that `git -c custom.ignorePostCommitHook=<WHATEVER HERE> commit ...` will suppress the hook

if git config --get custom.ignorePostCommitHook > /dev/null; then
    exit 0
fi

# otherwise run the hook

echo '+---------+'
echo '| H O O K |'
echo '+---------+'
like image 29
terrorrussia-keeps-killing Avatar answered Jul 18 '26 18:07

terrorrussia-keeps-killing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!