<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tips on MoskitoHero</title><link>https://moskitohero.com/tags/tips/</link><description>Recent content in Tips on MoskitoHero</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 01 Jun 2026 16:22:00 +0200</lastBuildDate><atom:link href="https://moskitohero.com/tags/tips/index.xml" rel="self" type="application/rss+xml"/><item><title>Directory-based git config rules</title><link>https://moskitohero.com/post/directory-based-git-config-rules/</link><pubDate>Mon, 01 Jun 2026 16:22:00 +0200</pubDate><guid>https://moskitohero.com/post/directory-based-git-config-rules/</guid><description>I have found a way to alter my git config based on the directory I am working from. Pretty simple, yet very handy.</description><content:encoded><![CDATA[<div class="paragraph">
<p>Like most devs, I use Git both for personal and work stuff, but I need to use distinct user details in each case to sign-off my commits. I have a global <code>.gitconfig</code> that define my personal email as <code>user.email</code>, but whenever I need to pull a new work project, I have to remember to set it to a different value locally. Which I keep forgetting to do.</p>
</div>
<div class="paragraph">
<p>So I have found a way to alter my git config based on the directory I am working from. All you need to do is add these lines to your <code>~/.gitconfig</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="toml"><span class="nn">[user]</span>
  <span class="py">name</span> <span class="p">=</span> <span class="err">My</span> <span class="err">Name</span>
  <span class="py">email</span> <span class="p">=</span> <span class="err">personal@email.com</span>

<span class="c"># Use work email for repositories under ~/dev/work</span>
<span class="nn">[includeIf &#34;gitdir:~/dev/work/&#34;]</span>
  <span class="py">path</span> <span class="p">=</span> <span class="err">~/.gitconfig-work</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>And edit <code>.gitconfig-work</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="toml"><span class="nn">[user]</span>
  <span class="py">email</span> <span class="p">=</span> <span class="err">work-email@mycompany.com</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>I think this also applies to other git config values, so feel free to experiment!</p>
</div>
]]></content:encoded></item></channel></rss>