GitKraken Desktop Documentation

Git Hooks in GitKraken Desktop

Last updated: March 2026

Use this page to create, configure, and troubleshoot Git hooks in GitKraken Desktop for commit, push, merge, and rebase workflows. It explains where hooks live, how custom hook paths work, which hook types GitKraken triggers, and how to bypass hooks intentionally when a commit should skip automation.

Requirements and limits

  • Scope: Standard Git hook workflows triggered by GitKraken Desktop actions
  • Default hook location: .git/hooks
  • macOS/Linux requirement: Hook files must be executable or GitKraken Desktop will fail to run them
  • Failure behavior: Any non-zero exit code blocks the Git action
  • Custom path support: Repository-specific custom hook paths can be configured in Preferences > Git Hooks
  • Global hook support: Global hooks can be configured through core.hooksPath in .gitconfig
  • Skip behavior: Commits can intentionally bypass hooks from the Commit Panel when needed
Overview of Git hooks and demonstration in GitKraken Desktop

Quick Start

  1. Navigate to your repository’s .git/hooks directory. GitKraken Desktop creates this folder automatically when a repository is initialized.
  2. Create a new file with the hook name (e.g., pre-commit). On macOS or Linux, make it executable by running chmod +x pre-commit in the terminal.
  3. Add your script to the file. Start with #!/bin/bash and include your validation or automation logic. Any non-zero exit code causes the hook to fail and blocks the Git action.
  4. To set a custom hooks directory for the repository, go to Preferences > Git Hooks and click Browse to select the folder.
  5. To use global hooks across all repositories, add hooksPath = /path/to/your/hooks under [core] in your .gitconfig.

To skip hooks for a specific commit, enable Commit and skip hooks in the Commit Panel. GitKraken Desktop supports pre-commit, commit-msg, post-commit, pre-push, post-merge, post-rewrite, and several other standard hooks.


Where Git hooks are stored

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.

Terminal output showing contents of the .git/hooks directory including various sample hook scripts
Terminal view of the .git/hooks directory
Finder window showing the path to the Git hooks directory within a repository's .git folder
Explorer view of the Git hooks directory

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.

Error notification in GitKraken Desktop indicating a pre-commit Git hook failed with exit code 126
Git hook execution error in GitKraken Desktop (exit code 126)

Any script that returns a non-zero exit code is considered a failure.


How to define a custom hook path

To use a custom Git hook path:

  1. Go to Preferences Git Hooks.
  2. Click to set or enter the path.

This setting is defined per repository.

GitKraken Desktop Preferences panel showing Git Hooks settings and custom directory option
Setting a custom Git hooks path in Preferences

Which hooks GitKraken Desktop supports

GitKraken Desktop supports a wide array of Git hooks. Each hook is triggered by specific actions like commit, merge, or rebase.

pre-commit

  • Amend
  • Commit
  • Merge Resolve

prepare-commit-msg

  • Amend
  • Commit
  • Cherrypick
  • Merge
  • Revert
  • Squash

commit-msg

  • Amend
  • Commit
  • Merge Resolve

post-commit

  • Amend
  • Cherrypick
  • Commit
  • Merge Resolve
  • Revert

pre-rebase

  • Rebase
  • Squash

post-checkout

  • Checkout
  • Discard Changes (selectively)

post-merge

  • Fast-Forward
  • Merge (Without Conflicts)

post-rewrite

  • Amend
  • Rebase
  • Squash

pre-push

  • Delete Remote Branch
  • Delete Remote Tag
  • Push Branch
  • Push Tag

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

How to set up a sample hook

1. Navigate to hooks directory
Open Visual Studio Code and go to ~/repo/.git/hooks. Create a new file named pre-commit.

VS Code file explorer showing the creation of a new pre-commit file inside the .git/hooks directory
Creating a new Git hook file in VS Code

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
GitKraken Desktop terminal changing into .git/hooks directory to make the pre-commit file executable
Making the pre-commit file executable using terminal

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 config
  • workEmail – 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.

What a Git hook looks like in action

GitKraken Desktop showing a pre-commit Git hook error after attempting to commit a staged file
Git hook example triggered during commit

How environment variables affect 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

How to 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.

GitKraken Desktop commit panel showing a checkbox to skip Git hooks during commit
Option to commit while skipping hooks in GitKraken Desktop

How global Git hooks work

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

Have feedback about this article? Did we miss something? Let us know!
On this page