DEV Community

Shawn
Shawn

Posted on

Versioned git-hooks with GitKraken in Windows 10

This short post will address an issue that I have been having with git-hooks in combination with GitKraken.

Let's say you have a project that requires git-hooks, for example for formatting, running tests, code analysis, etc... And you also want these git-hooks to be versioned by git. By default git stores all your git-hooks inside .git/hooks, but the .git folder is automatically ignored.

Now you ask: "Why would you want to version git-hooks?"
Well, Let's say you want to make sure that each developer on your project always formats his/her code. You would need to share your specific hook with each member and then if you need to change something to the hook you need to redistribute it again.


Git config

Luckily there is a way to provide git with an alternative location for your git-hooks by executing the following command:

git config core.hooksPath .githooks/
Enter fullscreen mode Exit fullscreen mode

And this works with most GUI clients out there like Sourcetree. But GitKraken does not take this into account and always looks at the default location namely .git/hooks

Symbolic link

Symbolic links to the rescue!
symlinks have been part of almost every operating system and to explain what these are very briefly is that they work as a point to another file or folder. There are some other types of symlinks but these are not relevant for the solution.

The idea is that you simply remove the hooks folder in your .git directory and then create a symlink with the name hooks that points to your versioned folder containing your actual git-hooks.

I use Windows 10 and I used the Link Shell Extension to have an extra item in my context menu.
context menu to pick source
Here you select the source folder which contains your hooks.
Then navigate to the .git folder and right-click again, now you can create your symbolic link
context menu create link

Make sure you rename the link to hooks.

After restarting GitKraken you can test out that it works
There you go, you're all set!

Top comments (0)