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. It is important to note that these 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.

If you are on 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 to let you know. Don't worry, we've got your back!

And if you are on Windows, GitKraken will detect your Git hooks as-is.


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