90 lines
6.4 KiB
Plaintext
90 lines
6.4 KiB
Plaintext
<p>From time to time I tend to forget what’s my effective Git configuration, so I have to
|
||
check it somehow. Most of the time I’d simply do the following:<sup id="fnref:1"><a class="footnote" href="https://batsov.com/articles/2021/11/14/display-git-configuration/#fn:1" rel="footnote">1</a></sup></p>
|
||
|
||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config <span class="nt">--list</span>
|
||
user.name<span class="o">=</span>Bozhidar Batsov
|
||
user.email<span class="o">=</span>bozhidar@example.org
|
||
pull.rebase<span class="o">=</span><span class="nb">true
|
||
</span>credential.username<span class="o">=</span>bbatsov
|
||
core.repositoryformatversion<span class="o">=</span>0
|
||
core.filemode<span class="o">=</span><span class="nb">true
|
||
</span>core.bare<span class="o">=</span><span class="nb">false
|
||
</span>core.logallrefupdates<span class="o">=</span><span class="nb">true
|
||
</span>remote.origin.url<span class="o">=</span>git@github.com:bbatsov/batsov.com.git
|
||
remote.origin.fetch<span class="o">=</span>+refs/heads/<span class="k">*</span>:refs/remotes/origin/<span class="k">*</span>
|
||
branch.master.remote<span class="o">=</span>origin
|
||
branch.master.merge<span class="o">=</span>refs/heads/master
|
||
</code></pre></div></div>
|
||
|
||
<p>This works great, but there’s one small problem with the output - it’s hard to figure out if something is a global setting
|
||
or a repo-specific setting. If only there was a way to show where each config value is coming from… Enter <code class="language-plaintext highlighter-rouge">--show-origin</code>:</p>
|
||
|
||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config <span class="nt">--list</span> <span class="nt">--show-origin</span>
|
||
file:/home/bozhidar/.gitconfig user.name<span class="o">=</span>Bozhidar Batsov
|
||
file:/home/bozhidar/.gitconfig user.email<span class="o">=</span>bozhidar@example.org
|
||
file:/home/bozhidar/.gitconfig pull.rebase<span class="o">=</span><span class="nb">true
|
||
</span>file:/home/bozhidar/.gitconfig credential.username<span class="o">=</span>bbatsov
|
||
file:.git/config core.repositoryformatversion<span class="o">=</span>0
|
||
file:.git/config core.filemode<span class="o">=</span><span class="nb">true
|
||
</span>file:.git/config core.bare<span class="o">=</span><span class="nb">false
|
||
</span>file:.git/config core.logallrefupdates<span class="o">=</span><span class="nb">true
|
||
</span>file:.git/config remote.origin.url<span class="o">=</span>git@github.com:bbatsov/batsov.com.git
|
||
file:.git/config remote.origin.fetch<span class="o">=</span>+refs/heads/<span class="k">*</span>:refs/remotes/origin/<span class="k">*</span>
|
||
file:.git/config branch.master.remote<span class="o">=</span>origin
|
||
file:.git/config branch.master.merge<span class="o">=</span>refs/heads/master
|
||
</code></pre></div></div>
|
||
|
||
<p>Now, that’s more like it! But wait, there’s more!</p>
|
||
|
||
<p>Since Git 2.26.0, you can use the <code class="language-plaintext highlighter-rouge">--show-scope</code> option to achieve a similar result:</p>
|
||
|
||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config <span class="nt">--list</span> <span class="nt">--show-scope</span>
|
||
|
||
system rebase.autosquash<span class="o">=</span><span class="nb">true
|
||
</span>system credential.helper<span class="o">=</span>helper-selector
|
||
global core.editor<span class="o">=</span>emacs
|
||
<span class="nb">local </span>core.symlinks<span class="o">=</span><span class="nb">false
|
||
local </span>core.ignorecase<span class="o">=</span><span class="nb">true</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It can be combined with <code class="language-plaintext highlighter-rouge">--show-origin</code> or the following flags:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">--local</code> for repository config</li>
|
||
<li><code class="language-plaintext highlighter-rouge">--global</code> for user config</li>
|
||
<li><code class="language-plaintext highlighter-rouge">--system</code> for all users’ config</li>
|
||
</ul>
|
||
|
||
<p>Pretty much everything related to <code class="language-plaintext highlighter-rouge">git config</code> can be combined with those flags.
|
||
Here’s how to list only the settings defined within the current repository:</p>
|
||
|
||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config <span class="nt">--list</span> <span class="nt">--show-origin</span> <span class="nt">--local</span>
|
||
file:.git/config core.repositoryformatversion<span class="o">=</span>0
|
||
file:.git/config core.filemode<span class="o">=</span><span class="nb">true
|
||
</span>file:.git/config core.bare<span class="o">=</span><span class="nb">false
|
||
</span>file:.git/config core.logallrefupdates<span class="o">=</span><span class="nb">true
|
||
</span>file:.git/config remote.origin.url<span class="o">=</span>git@github.com:bbatsov/batsov.com.git
|
||
file:.git/config remote.origin.fetch<span class="o">=</span>+refs/heads/<span class="k">*</span>:refs/remotes/origin/<span class="k">*</span>
|
||
file:.git/config branch.master.remote<span class="o">=</span>origin
|
||
file:.git/config branch.master.merge<span class="o">=</span>refs/heads/master
|
||
</code></pre></div></div>
|
||
|
||
<p>Of course, you can also consult specific settings if you remember their names:</p>
|
||
|
||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config user.email
|
||
bozhidar@example.org
|
||
<span class="nv">$ </span>git config <span class="nt">--show-origin</span> user.email
|
||
file:.git/config bozhidar@example.org
|
||
</code></pre></div></div>
|
||
|
||
<p>I rarely do this, as I’m struggling to remember even some of the basic config options, but your memory might be better than mine.</p>
|
||
|
||
<p>That’s all I’ve got for you today. I hope you learned something useful! I also hope I’ll finally remember <code class="language-plaintext highlighter-rouge">--show-scope</code>!</p>
|
||
|
||
<div class="footnotes">
|
||
<ol>
|
||
<li id="fn:1">
|
||
<p>Admittedly, first I’d often try <code class="language-plaintext highlighter-rouge">git config</code> and then start to wonder what was the proper command. <a class="reversefootnote" href="https://batsov.com/articles/2021/11/14/display-git-configuration/#fnref:1">↩</a></p>
|
||
</li>
|
||
</ol>
|
||
</div> |