<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Milad on Medium]]></title>
        <description><![CDATA[Stories by Milad on Medium]]></description>
        <link>https://medium.com/@miladpw?source=rss-8352ab341761------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*i8vGX_xp1HmjxZ4u5bduEA.jpeg</url>
            <title>Stories by Milad on Medium</title>
            <link>https://medium.com/@miladpw?source=rss-8352ab341761------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:53:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miladpw/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git Worktrees with Bare Repos: A Clean Setup for Modern Development]]></title>
            <link>https://medium.com/@miladpw/git-worktrees-with-bare-repos-a-clean-setup-for-modern-development-c5b251ee7b73?source=rss-8352ab341761------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5b251ee7b73</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[claude-code]]></category>
            <dc:creator><![CDATA[Milad]]></dc:creator>
            <pubDate>Mon, 06 Apr 2026 09:49:22 GMT</pubDate>
            <atom:updated>2026-04-06T09:49:22.055Z</atom:updated>
            <content:encoded><![CDATA[<p>If you hate clutter and the overhead of context switching as much as I do, then you’re in the right place. ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qRLQQRoyJDxZEluxJ7Oa_Q.png" /></figure><h3>The Problem</h3><p>When you work on monorepos or manage multiple feature branches simultaneously, you’ve probably hit the same wall: git only lets you have one branch checked out at a time. Context switching between branches means stashing work, checking out, dealing with rebuild times, and then switching back. It’s friction.</p><p>For developers juggling hotfixes, features, and maintenance branches in parallel, this becomes a real bottleneck.</p><h3>The Existing Solution: Git Worktrees</h3><p>Fortunately, git has a built-in solution: git worktree. Worktrees let you check out multiple branches simultaneously in different directories, all sharing the same .git history. Combined with bare clones, you get a clean setup where one directory holds the git metadata and sibling directories contain your actual work.</p><p>The typical pattern you see in the documentation and introduction to worktrees looks like this:</p><pre>git clone &lt;repo-url&gt; my-project<br>cd my-project<br>git worktree add ../feature-branch origin/feature-branch</pre><p>The basic setup works, but it has a large downside:</p><p><strong>Directory structure feels awkward</strong></p><p>The repo directory sits alongside the worktrees which results into clutter. And in the current world of AI tools, this means your nice little agent running on your main branch ends up having copies of the codebase checked out from different branches in different worktrees.</p><h3>The Solution I Came Up With</h3><p>I’ve refined this workflow into something cleaner and more ergonomic. Here’s the complete setup:</p><h3>Step 1: Clone as Bare with Single Branch</h3><pre>git clone --bare --single-branch &lt;repo-url&gt; my-project/.git</pre><p>Beware of the clone path. We’re cloning into .git directly. This makes your project root <em>itself</em> the git repository, with only .git/containing the git internals. No extra directory.</p><h3>Step 2: Configure Remote Tracking</h3><p>With --single-branch, git only fetches main. We need all remote branches available as refs:</p><pre>git config remote.origin.fetch &#39;+refs/heads/*:refs/remotes/origin/*&#39;<br>git fetch origin</pre><p>This tells git to fetch all branches as remote-tracking refs (origin/branch-name) without creating local branches.</p><h3>Step 3: Create Worktrees</h3><pre>git worktree add main main<br>git worktree add feature-auth origin/feature-auth<br>git worktree add bugfix-cache origin/bugfix-cache</pre><h3>The Result</h3><p>Your project structure is now:</p><pre>my-project/<br>├── .git/                    (git internals only)<br>├── main/                    (main branch checkout)<br>├── feature-auth/            (feature branch checkout)<br>└── bugfix-cache/            (bugfix branch checkout)</pre><h3>Why This Is Better</h3><p><strong>Clean local branch listing</strong> — git branch shows only main. All other branches exist as remote refs (origin/branch-name), keeping noise out of your workflow.</p><p><strong>No fetch friction</strong> — Remote branches are configured upfront. When you need to work on a new branch, just run git worktree add directory-name origin/new-branch and you&#39;re done.</p><p><strong>IDE-friendly</strong> — Each worktree opens in its own editor window. For Claude Code or VSCode, you get isolated contexts without path confusion.</p><p><strong>Single git database</strong> — All worktrees share one .git/, saving disk space and keeping your setup simple. No multiple clones, no duplicate history.</p><h3>The Complete Setup Script</h3><pre># Clone as bare into .git<br>git clone --bare --single-branch &lt;repo-url&gt; my-project .git<br><br># Configure remote tracking<br>git config remote.origin.fetch &#39;+refs/heads/*:refs/remotes/origin/*&#39;<br>git fetch origin<br><br># Create work directories<br>mkdir -p work/{current,features,maintenance}<br><br># Add main worktree<br>git worktree add work/current main<br><br># Verify setup<br>git branch        # shows only main<br>git branch -a     # shows all remote branches<br>git worktree list # shows all active worktrees</pre><h3>Daily Workflow</h3><p>Create new worktrees as needed:</p><pre>git worktree add my-feature origin/my-feature<br><br># Or create from a new branch<br>git worktree add -b my-feature my-feature main<br><br># Work normally<br>cd my-feature<br>code my-feature<br>git commit -am &quot;changes&quot;<br>git push<br><br># When done<br>git worktree remove my-feature</pre><h3>Caveats</h3><p>Each worktree is independent — if you have a monorepo with shared dependencies, you’ll need to run npm install (or equivalent) in each worktree.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5b251ee7b73" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>