Git hooks

Git hooks are shell scripts that execute after an event such as a commit or push.

In the following video, we will take you through the basics of what a Git hook is and demonstrate how to use one in GitKraken.


Where are Git hooks?

Hooks are stored in the hooks subdirectory of the .git directory. This folder is automatically created when you initialize a new repository in GitKraken and is located in .git\hooks in your project directory.

Hooks are unique to your local repository and will not be copied over if you create a new repository. Feel free to add, change, or remove scripts from this folder as necessary.

<img src='/img/documentation/repositories/githooks/hook_location.png' srcset='/img/documentation/repositories/githooks/hook_location@2x.png 2x' class='img-responsive center img-bordered'

If running OSX or Linux, GitKraken will seamlessly detect any Git hooks in your repository if your scripts are set to be executable. If you forgot to set your files to executables, GitKraken will throw an error as a heads up.

And if running Windows, GitKraken will detect your Git hooks automatically.


What hooks are supported by GitKraken?

Here are the hooks support by GitKraken. Where appropriate, beneath each hook are the actions during which GitKraken calls that hook:

pre-commit

- Commit
- Amend
- Merge Resolve

prepare-commit-msg

- Commit
- Amend
- Cherrypick
- Merge
- Squash
- Revert

commit-msg

- Commit
- Amend
- Merge Resolve

post-commit

- Commit
- Amend
- Cherrypick
- Merge Resolve
- Revert

pre-rebase

- Rebase
- Squash

post-checkout

- Checkout
- Discard Changes (selectively)

post-merge

- Merge (Without Conflicts)
- Fast-Forward

post-rewrite

- Amend
- Squash
- Rebase

pre-push

- Push Branch
- Push Tag
- Delete Remote Branch
- Delete Remote Tag