<?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>Git-Worktree on Kinoko's TIL Log</title><link>https://kinoko-tech-blog-theta.vercel.app/tags/git-worktree/</link><description>Recent content in Git-Worktree on Kinoko's TIL Log</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>pippimotta@gmail.com (Kinoko)</managingEditor><webMaster>pippimotta@gmail.com (Kinoko)</webMaster><copyright>&amp;copy; Brewed by Kinoko</copyright><lastBuildDate>Thu, 11 Jun 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://kinoko-tech-blog-theta.vercel.app/tags/git-worktree/index.xml" rel="self" type="application/rss+xml"/><item><title>Git Worktree Mental Model -- Shared Object Store and Branch Lock</title><link>https://kinoko-tech-blog-theta.vercel.app/posts/git-worktree-mental-model-shared-object-store-and-branch-lock/</link><pubDate>Thu, 11 Jun 2026 00:00:00 +0000</pubDate><author>pippimotta@gmail.com (Kinoko)</author><guid>https://kinoko-tech-blog-theta.vercel.app/posts/git-worktree-mental-model-shared-object-store-and-branch-lock/</guid><description>&lt;h2 id="the-point"&gt;The Point&lt;/h2&gt;
&lt;p&gt;A git worktree is not a repo copy. It checks out an independent working directory (with its own HEAD + index) from a shared .git object store. This architecture is what drives the branch:worktree 1:1 lock and the &amp;ldquo;cd instead of git switch&amp;rdquo; workflow.&lt;/p&gt;
&lt;h2 id="explanation"&gt;Explanation&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;.git&lt;/code&gt; inside a new worktree directory is a file, not a folder. It contains a single line: &lt;code&gt;gitdir: &amp;lt;main repo&amp;gt;/.git/worktrees/&amp;lt;name&amp;gt;/&lt;/code&gt;, pointing back to the main repo&amp;rsquo;s object store. All immutable git data (blobs, trees, commits, remote config) lives in the main &lt;code&gt;.git/&lt;/code&gt; and is shared. Each worktree only owns an independent HEAD and index (staging area). Because the index is per-worktree, git enforces that the same branch can only be checked out by one worktree at a time &amp;ndash; otherwise two worktrees running &lt;code&gt;git add&lt;/code&gt; simultaneously would overwrite each other&amp;rsquo;s staging state. So in a multi-worktree setup, &amp;ldquo;looking at another branch&amp;rsquo;s code&amp;rdquo; means &lt;code&gt;cd&lt;/code&gt;-ing to the corresponding directory, not running &lt;code&gt;git switch&lt;/code&gt;.&lt;/p&gt;</description><content:encoded><![CDATA[<h2 id="the-point">The Point</h2>
<p>A git worktree is not a repo copy. It checks out an independent working directory (with its own HEAD + index) from a shared .git object store. This architecture is what drives the branch:worktree 1:1 lock and the &ldquo;cd instead of git switch&rdquo; workflow.</p>
<h2 id="explanation">Explanation</h2>
<p>The <code>.git</code> inside a new worktree directory is a file, not a folder. It contains a single line: <code>gitdir: &lt;main repo&gt;/.git/worktrees/&lt;name&gt;/</code>, pointing back to the main repo&rsquo;s object store. All immutable git data (blobs, trees, commits, remote config) lives in the main <code>.git/</code> and is shared. Each worktree only owns an independent HEAD and index (staging area). Because the index is per-worktree, git enforces that the same branch can only be checked out by one worktree at a time &ndash; otherwise two worktrees running <code>git add</code> simultaneously would overwrite each other&rsquo;s staging state. So in a multi-worktree setup, &ldquo;looking at another branch&rsquo;s code&rdquo; means <code>cd</code>-ing to the corresponding directory, not running <code>git switch</code>.</p>
<h2 id="knowledge-sugar">Knowledge Sugar</h2>
<p>The difference between a worktree and a clone is that a clone copies the entire object database, while a worktree shares it. Docker analogy: clone is like <code>docker save</code> + <code>docker load</code> (a full copy of image layers); worktree is like running a second container from the same image (shared layers, just one more writable layer on top). In large repos where <code>.git/</code> can be hundreds of MB, the savings are significant.</p>
<p>Useful operations: <code>git worktree list</code> shows all worktrees and their branch bindings; <code>cat &lt;worktree-dir&gt;/.git</code> directly verifies the pointer relationship; when you no longer need a worktree, <code>git worktree remove &lt;path&gt;</code> releases the branch lock &ndash; only then can you <code>git switch</code> to that branch from the main worktree.</p>
<p>Claude Code&rsquo;s design of auto-opening worktrees is worth noting: it avoids touching the state of your current working directory, so it opens an isolated environment to make changes &ndash; the same isolation principle as CI not running builds directly on a developer&rsquo;s checkout.</p>
]]></content:encoded></item></channel></rss>