title: Why does Git execute hooks from an other repository?
body: <p>With this MWE Git executes hooks in a the wrong repository (<code>A</code>):</p>
  <pre class="lang-sh prettyprint-override"><code># Make simple repo
  git init &quot;/tmp/A&quot; &amp;&amp; cd &quot;/tmp/A&quot; || exit 1
  
  # Make hook to demonstrate the problem
  mkdir -p &quot;.git/hooks&quot; &amp;&amp;
      echo &quot;echo 'EXECUTED!!!'&quot; &gt;.git/hooks/reference-transaction &amp;&amp;
      chmod +x &quot;.git/hooks/reference-transaction&quot; &amp;&amp;
      git clone -c core.hooksPath=&quot;.git/hooks&quot; --template= &quot;https://github.com/gabyx/Githooks.git&quot; /tmp/Githooks
  </code></pre>
  <p>Results in</p>
  <pre><code>Initialized empty Git repository in /home/test/tmp/A/.git/
  Cloning into 'Githooks'...
  EXECUTED!!!
  EXECUTED!!!
  EXECUTED!!!
  EXECUTED!!!
  </code></pre>
  <p>Which is totally weird: I expect <code>git clone</code> to execute the hook in <code>/tmp/Githooks/.git/hooks</code> because from</p>
  <p><a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath" rel="nofollow noreferrer"><code>core.hooksPath</code></a></p>
  <blockquote>
  <p>The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run (see the &quot;DESCRIPTION&quot; section of githooks[5]).</p>
  </blockquote>
  <p>and further in <a href="https://git-scm.com/docs/githooks" rel="nofollow noreferrer">Doc</a> :</p>
  <blockquote>
  <p>Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.</p>
  </blockquote>
  <p>Why is this, and is this a Bug which should be reported?</p>