{"meta":{"title":"Working with pre-receive hooks","intro":"Enforce repository policies and prevent issues like secrets or invalid commits using pre-receive hooks on GitHub Enterprise Server.","product":"Pull requests","breadcrumbs":[{"href":"/en/enterprise-server@3.19/pull-requests","title":"Pull requests"},{"href":"/en/enterprise-server@3.19/pull-requests/reference","title":"Reference"},{"href":"/en/enterprise-server@3.19/pull-requests/reference/working-with-pre-receive-hooks","title":"Pre-receive hooks"}],"documentType":"article"},"body":"# Working with pre-receive hooks\n\nEnforce repository policies and prevent issues like secrets or invalid commits using pre-receive hooks on GitHub Enterprise Server.\n\nPre-receive hooks are scripts that run on GitHub Enterprise Server before Git accepts pushed commits. They enforce repository, organization, or enterprise policy at the point where code enters a repository.\n\nA pre-receive hook can check whether a push follows required rules. For example, a hook might block pushes that include secrets, use nonstandard commit messages, or change protected files. If the push passes the checks, Git accepts it. If the push fails, Git rejects it and shows an error message.\n\nIf your push isn't accepted, you'll see an error message for the failed pre-receive hook.\n\n```shell\n$ git push\nCounting objects: 3, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (3/3), 916 bytes | 0 bytes/s, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nremote: always_reject.sh: failed with exit status 1\nremote: error: rejecting all pushes\nTo https://54.204.174.51/hodor/nope.git\n ! [remote rejected] main -> main (pre-receive hook declined)\nerror: failed to push some refs to 'https://54.204.174.51/hodor/nope.git'\n```\n\nPre-receive hooks matter because they apply rules consistently before changes reach the repository. This can reduce manual review burden and prevent policy violations from being stored in Git history.\n\nYour GitHub Enterprise Server site administrator creates and removes pre-receive hooks. They may also allow organization or repository administrators to enable or disable hooks for specific scopes. See [Enforcing policy with pre-receive hooks](/en/enterprise-server@3.19/admin/enforcing-policies/enforcing-policy-with-pre-receive-hooks)."}