<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shawn</title>
    <description>The latest articles on DEV Community by Shawn (@shawnrg).</description>
    <link>https://dev.to/shawnrg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F520935%2Fe73d83aa-e2ef-4ba5-a989-248bcbc6b561.png</url>
      <title>DEV Community: Shawn</title>
      <link>https://dev.to/shawnrg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shawnrg"/>
    <language>en</language>
    <item>
      <title>Versioned git-hooks with GitKraken in Windows 10</title>
      <dc:creator>Shawn</dc:creator>
      <pubDate>Fri, 30 Apr 2021 12:13:20 +0000</pubDate>
      <link>https://dev.to/shawnrg/versioned-git-hooks-with-gitkraken-1nnp</link>
      <guid>https://dev.to/shawnrg/versioned-git-hooks-with-gitkraken-1nnp</guid>
      <description>&lt;p&gt;This short post will address an issue that I have been having with git-hooks in combination with GitKraken. &lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;.git/hooks&lt;/code&gt;, but the &lt;code&gt;.git&lt;/code&gt; folder is automatically ignored.&lt;/p&gt;

&lt;p&gt;Now you ask: "&lt;em&gt;Why would you want to version git-hooks?&lt;/em&gt;"&lt;br&gt;
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.&lt;/p&gt;


&lt;h2&gt;
  
  
  Git config
&lt;/h2&gt;

&lt;p&gt;Luckily there is a way to provide git with an alternative location for your git-hooks by executing the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config core.hooksPath .githooks/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;.git/hooks&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Symbolic link
&lt;/h2&gt;

&lt;p&gt;Symbolic links to the rescue! &lt;br&gt;
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.&lt;/p&gt;

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

&lt;p&gt;I use Windows 10 and I used the &lt;a href="https://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html" rel="noopener noreferrer"&gt;Link Shell Extension&lt;/a&gt; to have an extra item in my context menu.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fci32d80w3g70iv1f1t32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fci32d80w3g70iv1f1t32.png" alt="context menu to pick source"&gt;&lt;/a&gt;&lt;br&gt;
Here you select the source folder which contains your hooks.&lt;br&gt;
Then navigate to the &lt;code&gt;.git&lt;/code&gt; folder and right-click again, now you can create your symbolic link&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3ymp59c0rgu2id8kg28.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3ymp59c0rgu2id8kg28.png" alt="context menu create link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure you rename the link to &lt;code&gt;hooks&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After restarting GitKraken you can test out that it works&lt;br&gt;
There you go, you're all set! &lt;/p&gt;

</description>
      <category>gitkraken</category>
      <category>githooks</category>
    </item>
  </channel>
</rss>
