<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sotaro KARASAWA</title>
    <description>The latest articles on DEV Community by Sotaro KARASAWA (@sotarok).</description>
    <link>https://dev.to/sotarok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F42463%2Fe3e98bba-a7db-44d8-8ebd-6c253bd212d7.png</url>
      <title>DEV Community: Sotaro KARASAWA</title>
      <link>https://dev.to/sotarok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sotarok"/>
    <language>en</language>
    <item>
      <title>I Created a gw Command to Make Git Worktree More User-Friendly</title>
      <dc:creator>Sotaro KARASAWA</dc:creator>
      <pubDate>Tue, 19 Aug 2025 15:13:15 +0000</pubDate>
      <link>https://dev.to/sotarok/i-created-a-gw-command-to-make-git-worktree-more-user-friendly-4jeb</link>
      <guid>https://dev.to/sotarok/i-created-a-gw-command-to-make-git-worktree-more-user-friendly-4jeb</guid>
      <description>&lt;p&gt;I made it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sotarok/gw" rel="noopener noreferrer"&gt;https://github.com/sotarok/gw&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Git Worktree is convenient, isn’t it?&lt;/li&gt;
&lt;li&gt;But I can’t remember the commands for some reason&lt;/li&gt;
&lt;li&gt;Essentially, what I want to do is start and end worktrees with “let’s do it” and “done”&lt;/li&gt;
&lt;li&gt;Plus there are quite a few tedious associated tasks (like running npm install)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I wanted something to support that feeling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Similar Tools
&lt;/h2&gt;

&lt;p&gt;After I started building this, I learned that someone was creating a much cooler integrated management tool called ccmanager.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kbwo/ccmanager" rel="noopener noreferrer"&gt;https://github.com/kbwo/ccmanager&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I thought “this would be fine,” but gw is more of a primitive tool that just makes git worktree work nicely.&lt;/p&gt;

&lt;p&gt;Also, well, in times like these, I thought it might be okay to reinvent the wheel a lot, so I decided to create something that’s easy for me to use in my own way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;The functionality is quite simple - it just handles adding and removing git worktrees based on issue numbers like this:&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a worktree
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gw start 123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a worktree for issue #123.&lt;/p&gt;

&lt;p&gt;When you do this, it creates a nice worktree directory named &lt;code&gt;gw-{issueNumber}&lt;/code&gt; like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sotarok
├── gw
├── gw-123
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to specify a base branch, just append it at the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Working on 123 branched from 122/impl branch
gw start 123 122/impl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Finishing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gw end 123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don’t include 123, it enters interactive mode where you can select.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking out
&lt;/h3&gt;

&lt;p&gt;Sometimes when reviewing, you want to bring someone else’s branch locally without polluting your local repository to check various things, right?&lt;/p&gt;

&lt;p&gt;In such cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gw checkout branch/name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can directly specify the branch name like this, and it will create a worktree for that purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra Features
&lt;/h2&gt;

&lt;p&gt;There’s no end to these kinds of additions, but I end up wanting to create them anyway, so I keep adding more and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatically running setup scripts
&lt;/h3&gt;

&lt;p&gt;I wanted npm install or pnpm install to run automatically when doing &lt;code&gt;gw start/checkout&lt;/code&gt;, so I made it do that.&lt;/p&gt;

&lt;p&gt;It supports npm, yarn, pnpm, cargo, go, pip, and bundler.&lt;/p&gt;

&lt;h3&gt;
  
  
  Copy env
&lt;/h3&gt;

&lt;p&gt;I want &lt;code&gt;.env&lt;/code&gt; or &lt;code&gt;.env.local&lt;/code&gt; to be automatically copied into the worktree.&lt;/p&gt;

&lt;p&gt;So it copies them.&lt;/p&gt;

&lt;p&gt;You can either add &lt;code&gt;--copy-envs&lt;/code&gt; when doing start/checkout, or if not specified, it will ask you.&lt;/p&gt;

&lt;p&gt;With these two behaviors working, you can just do &lt;code&gt;gw start&lt;/code&gt; and immediately get to work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auto cd
&lt;/h3&gt;

&lt;p&gt;Automatically moves to that directory when you do &lt;code&gt;gw start/checkout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Shell integration is required. The behavior can be controlled via config.&lt;/p&gt;

&lt;p&gt;It’s good to add something like this to your &lt;code&gt;.zshrc&lt;/code&gt;. It supports bash/zsh/fish. (Probably. I’ve only tested it with zsh)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;gw shell-integration &lt;span class="nt"&gt;--show-script&lt;/span&gt; &lt;span class="nt"&gt;--shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;zsh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  iTerm2 integration
&lt;/h3&gt;

&lt;p&gt;When working on multiple things in parallel, you end up with lots of iTerm2 tabs and forget what you’re doing where, so it updates the iTerm2 tab name to &lt;code&gt;repositoryName {issueNumber}&lt;/code&gt;. The behavior can be controlled via config.&lt;/p&gt;

&lt;p&gt;Mac only.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auto-delete head branch when ending worktree
&lt;/h3&gt;

&lt;p&gt;I was bothered by local branches remaining when doing worktree remove. Now it auto-deletes them.&lt;/p&gt;

&lt;p&gt;The behavior can be controlled via config.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the gw command itself was made
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Made with go&lt;/li&gt;
&lt;li&gt;But I didn’t write a single line myself… hehe… (I made it, or rather had it made… I guess)&lt;/li&gt;
&lt;li&gt;I’ve been adding features during work breaks and whenever I think of something&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Actual Workflow (Use Case)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Find an issue I want to work on&lt;/li&gt;
&lt;li&gt;Open a new iTerm2 tab&lt;/li&gt;
&lt;li&gt;Navigate to the repository&lt;/li&gt;
&lt;li&gt;Do &lt;code&gt;gw start&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Split the screen with tmux and work with claude etc.&lt;/li&gt;
&lt;li&gt;After finishing work and getting to merge, do &lt;code&gt;end&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Something like that.&lt;/p&gt;

&lt;p&gt;What I personally like is that &lt;code&gt;gw&lt;/code&gt; is very easy to type.&lt;/p&gt;

&lt;p&gt;Please try it out if you’d like.&lt;/p&gt;

</description>
      <category>git</category>
      <category>cli</category>
      <category>go</category>
    </item>
  </channel>
</rss>
