Last updated: May 2025
Git hooks are shell scripts that execute after Git events such as commits or pushes.
Where are Git hooks?
Hooks reside in the hooks
subdirectory of the .git
folder, created automatically when initializing a repository in GitKraken Desktop. You’ll find it at .git/hooks
, typically containing a README.sample
file.
Hooks are specific to your local repository and are neither tracked by Git nor copied to new repositories.


If you’re on OSX or Linux, you must set hook files to be executable. GitKraken Desktop will throw an error (e.g., exit code 126) if the file lacks executable permissions.

Any script that returns a non-zero exit code is considered a failure.
Define a custom hook path
To use a custom Git hook path:
- Go to Preferences Git Hooks.
- Click to set or enter the path.
This setting is defined per repository.

What hooks are supported by GitKraken Desktop?
GitKraken Desktop supports a wide array of Git hooks. Each hook is triggered by specific actions like commit, merge, or rebase.
Git hooks example
Git hooks automate actions when Git events occur in GitKraken Desktop or the command line. Here’s a basic pre-commit
hook example to validate the global Git user email.
Tools needed
- GitKraken Desktop
- Text Editor (e.g., Visual Studio Code)
- Terminal (e.g., GitKraken Terminal)
Step-by-step setup
1. Navigate to hooks directory
Open Visual Studio Code and go to ~/repo/.git/hooks. Create a new file named pre-commit
.

Note 📝 – You may need to make the .git folder visible in VS Code by adjusting files.exclude
settings.
2. Make the file executable
Open the GitKraken Terminal and change to the .git/hooks
directory. Run:
chmod +x pre-commit

Note 📝 – If your terminal isn’t set up in GitKraken Desktop, refer to the Start Here Tips.
3. Write your bash script
Use a text editor to define your pre-commit
script. Start with the correct shebang:
#!/bin/bash
Then add your validation logic using variables like:
globalEmail
– value from Git global configworkEmail
– required email for commits
The script should compare the current global email with the required email and display an error if they do not match. If the values match, the commit proceeds.
Example:
#!/bin/bash
globalEmail=$(git config --global user.email)
workEmail="[email protected]"
if [ "$globalEmail" != "$workEmail" ]; then
echo "Error: global email does not match required work email ($workEmail)."
exit 1
fi
exit 0
Save the file. Your pre-commit
hook is now ready to enforce proper committer email usage before any commit is made.
Git hook in action

Environment Variables & Git Hooks
On macOS, GUI applications do not inherit shell profile variables. If your Git hooks rely on environment variables set in your shell, use the following command to make them available:
launchctl setenv YOURVAR value
Bypass Git hooks
To skip Git hooks during a commit, use the Commit and skip hooks
option.
Note 📝 – This option disables all hooks triggered by the commit action.

Global Git Hooks
GitKraken Desktop respects global Git hook paths set in your .gitconfig
file. These hooks apply to all cloned repositories.
To configure a global path, add the following to your .gitconfig
:
[core]
hooksPath = /path/to/your/hooks