<?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/" xmlns:blog="https://jonesrussell.github.io/blog/ns"><channel><title>Version-Control on Web Developer Blog</title><link>https://jonesrussell.github.io/blog/tags/version-control/</link><description>Recent content in Version-Control on Web Developer Blog</description><image><title>Web Developer Blog</title><url>https://jonesrussell.github.io/blog/images/og-default.png</url><link>https://jonesrussell.github.io/blog/images/og-default.png</link></image><generator>Hugo -- 0.164.0</generator><language>en-us</language><lastBuildDate>Wed, 15 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://jonesrussell.github.io/blog/tags/version-control/feed.xml" rel="self" type="application/rss+xml"/><item><title>A beginner's guide to Git worktrees: What they are, why they matter, and how to use them without breaking anything</title><link>https://jonesrussell.github.io/blog/beginners-guide-git-worktrees/</link><pubDate>Wed, 15 Apr 2026 00:00:00 +0000</pubDate><guid>https://jonesrussell.github.io/blog/beginners-guide-git-worktrees/</guid><category>general</category><blog:tag>git</blog:tag><blog:tag>git-worktree</blog:tag><blog:tag>version-control</blog:tag><blog:tag>beginner-guide</blog:tag><description>Learn what Git worktrees are, why they exist, and how to use them safely with a beginner-friendly workflow.</description><content:encoded><![CDATA[<p>Ahnii!</p>
<p>If you have ever needed to work on two branches at the same time, Git worktrees can save you a lot of friction. This post covers what worktrees are, why they exist, and how you can use them safely as a beginner.</p>
<h2 id="prerequisites">Prerequisites</h2>
<ul>
<li>You have <a href="https://git-scm.com/">Git</a> installed</li>
<li>You can run commands in your terminal</li>
<li>You already have a local repository</li>
</ul>
<h2 id="what-is-a-git-worktree">What Is a Git Worktree?</h2>
<p>A Git worktree is an extra working folder connected to the same repository history.<br>
You can think of it as another checkout of your project, without making another full clone.</p>
<p>Your main folder still exists. A worktree gives you a second folder where a different branch can be checked out at the same time.</p>
<h2 id="why-worktrees-exist">Why Worktrees Exist</h2>
<p>Git worktrees solve a practical problem. You may be in the middle of feature work, then need to fix a bug on another branch right away.</p>
<p>Without worktrees, you usually do one of these:</p>
<ul>
<li>Stash or commit unfinished work, then switch branches</li>
<li>Open a second full clone of the same repository</li>
</ul>
<p>Both options work, but both add overhead. Worktrees give you a cleaner path.</p>
<h2 id="normal-clone-vs-branch-checkout-vs-worktree">Normal Clone vs Branch Checkout vs Worktree</h2>
<p>Here is the simple difference:</p>
<h3 id="normal-clone">Normal clone</h3>
<p>A clone is a separate copy of a repository with its own <code>.git</code> directory.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git clone https://github.com/example/project.git
</span></span></code></pre></div><p>You use this when you need the repository on your machine for the first time. It is fully independent from other clones.</p>
<h3 id="branch-checkout">Branch checkout</h3>
<p>A branch checkout changes which branch is active in your current folder.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git checkout feature/foo
</span></span></code></pre></div><p>This is fast, but only one branch can be active in that folder at a time.</p>
<h3 id="worktree">Worktree</h3>
<p>A worktree creates another folder tied to the same repository, usually on a different branch.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree add ../feature-foo feature/foo
</span></span></code></pre></div><p>Now you have two folders open at once: your main folder and <code>../feature-foo</code>. Each can point at a different branch.</p>
<h2 id="core-benefits-of-worktrees">Core Benefits of Worktrees</h2>
<h3 id="1-multiple-branches-checked-out-at-once">1) Multiple branches checked out at once</h3>
<p>You can keep your main branch open in one folder and your feature branch in another.<br>
No constant branch switching.</p>
<h3 id="2-isolated-environments-for-experiments">2) Isolated environments for experiments</h3>
<p>You can test risky changes in one worktree without touching the working state in another folder.</p>
<h3 id="3-no-need-for-multiple-full-clones">3) No need for multiple full clones</h3>
<p>Worktrees share repository data, so you avoid duplicate clones for everyday branch work.</p>
<h2 id="a-safe-beginner-workflow">A Safe Beginner Workflow</h2>
<p>This is a clean workflow you can use right away.</p>
<h3 id="1-create-a-worktree">1) Create a worktree</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree add ../feature-foo feature/foo
</span></span></code></pre></div><p>This command creates a new folder named <code>../feature-foo</code> and checks out <code>feature/foo</code> there.<br>
If <code>feature/foo</code> does not exist yet, create it first with <code>git branch feature/foo</code>.</p>
<h3 id="2-switch-into-it">2) Switch into it</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cd ../feature-foo
</span></span></code></pre></div><p>Now every Git command runs inside that worktree folder.<br>
Before you edit files, confirm where you are with <code>pwd</code> and <code>git branch --show-current</code>.</p>
<h3 id="3-commit-from-it">3) Commit from it</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git add .
</span></span><span style="display:flex;"><span>git commit -m <span style="color:#e6db74">&#34;Add first pass of feature foo&#34;</span>
</span></span></code></pre></div><p>These commits belong to the branch checked out in that worktree.<br>
You do not need to return to your original folder to commit.</p>
<h3 id="4-remove-it-safely">4) Remove it safely</h3>
<p>First leave the worktree folder, then remove it with Git.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cd ../your-main-repo
</span></span><span style="display:flex;"><span>git worktree remove ../feature-foo
</span></span></code></pre></div><p>This tells Git to unregister the worktree and remove the directory safely.<br>
Always prefer this over deleting the folder manually.</p>
<h2 id="how-to-see-your-current-worktrees">How to See Your Current Worktrees</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree list
</span></span></code></pre></div><p>This shows every registered worktree path and branch.<br>
Use this often, especially when you are learning.</p>
<h2 id="common-beginner-mistakes">Common Beginner Mistakes</h2>
<h3 id="deleting-the-directory-without-removing-the-worktree">Deleting the directory without removing the worktree</h3>
<p>If you run <code>rm -rf</code> on a worktree folder first, Git can keep stale metadata.<br>
Remove worktrees with <code>git worktree remove &lt;path&gt;</code> whenever possible.</p>
<h3 id="forgetting-which-worktree-you-are-in">Forgetting which worktree you are in</h3>
<p>It is easy to commit to the wrong branch when two folders look similar.<br>
Check <code>pwd</code> and <code>git branch --show-current</code> before making changes.</p>
<h3 id="trying-to-check-out-the-same-branch-twice">Trying to check out the same branch twice</h3>
<p>Git does not allow the same branch to be active in two worktrees at once.<br>
Create a new branch if you need a second experimental space.</p>
<h2 id="a-simple-mental-model-for-gitworktrees">A Simple Mental Model for <code>.git/worktrees</code></h2>
<p>Your main repository still has the real Git database.<br>
Inside it, <code>.git/worktrees</code> stores small records that point to each extra working folder.</p>
<p>Think of it like a clipboard that says:</p>
<ul>
<li>Which extra folders exist</li>
<li>Which branch each one uses</li>
<li>Whether Git still expects them to be present</li>
</ul>
<p>That is why manual deletion can confuse Git. The clipboard still has an entry, even if the folder is gone.</p>
<h2 id="how-to-clean-up-orphaned-worktrees">How to Clean Up Orphaned Worktrees</h2>
<p>Sometimes a worktree folder gets deleted outside Git.<br>
You can clean this up safely in a few steps.</p>
<h3 id="step-1-list-what-git-thinks-exists">Step 1: List what Git thinks exists</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree list
</span></span></code></pre></div><p>Look for paths that no longer exist on disk.<br>
Those are likely orphans.</p>
<h3 id="step-2-prune-stale-metadata">Step 2: Prune stale metadata</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree prune
</span></span></code></pre></div><p>This removes stale worktree entries that no longer point to valid folders.<br>
It is a safe maintenance command for this situation.</p>
<h3 id="step-3-verify-cleanup">Step 3: Verify cleanup</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree list
</span></span></code></pre></div><p>Run the list command again to confirm orphan entries are gone.<br>
If everything looks clean, you are done.</p>
<h2 id="verify-it-works">Verify It Works</h2>
<p>Run this quick check whenever you start using worktrees:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git worktree list
</span></span><span style="display:flex;"><span>git branch --show-current
</span></span><span style="display:flex;"><span>pwd
</span></span></code></pre></div><p>These three commands tell you what worktrees exist, which branch is active, and which folder you are in.<br>
That simple habit prevents most beginner mistakes.</p>
<p>Baamaapii</p>
]]></content:encoded></item></channel></rss>