Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sotarok/gw

Repository files navigation

gw - Git Worktree CLI Tool

CI Release Go Report Card License: MIT

A convenient CLI tool for managing Git worktrees with automatic package manager setup.

Features

  • Create worktrees with simple commands
  • Checkout existing branches as worktrees
  • Automatic detection and setup of package managers (npm, yarn, pnpm, cargo, go, pip, bundler)
  • Copy untracked environment files (.env, .env.local, etc.) to new worktrees
  • Interactive worktree selection for removal
  • Interactive branch selection for checkout
  • Safety checks before removing worktrees (uncommitted changes, unpushed commits, merge status)
  • Cross-platform support (macOS, Linux)

Installation

Using go install

go install github.com/sotarok/gw@latest

Download Binary

Download the latest binary for your platform from the Releases page.

Linux

# AMD64
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Linux_x86_64.tar.gz | tar xz
sudo mv gw /usr/local/bin/

# ARM64
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Linux_arm64.tar.gz | tar xz
sudo mv gw /usr/local/bin/

macOS

# Intel Mac
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Darwin_x86_64.tar.gz | tar xz
sudo mv gw /usr/local/bin/

# Apple Silicon
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Darwin_arm64.tar.gz | tar xz
sudo mv gw /usr/local/bin/

From source

git clone https://github.com/sotarok/gw.git
cd gw
make install

Usage

Create a new worktree

# Create worktree for issue #123 based on main branch
gw start 123

# Create worktree based on specific branch
gw start 456 develop

# Create worktree and copy environment files
gw start 789 --copy-envs

This will:

  1. Create a new worktree at ../{repository-name}-{issue-number}
  2. Create a new branch {issue-number}/impl
  3. Change to the new worktree directory
  4. Optionally copy untracked .env files from the original repository
  5. Automatically run package manager setup if detected

Checkout an existing branch

# Checkout specific branch as worktree
gw checkout feature/auth

# Checkout remote branch
gw checkout origin/feature/api

# Interactive mode - select from list of branches
gw checkout

# Checkout and copy environment files
gw checkout feature/auth --copy-envs

This will:

  1. Create a new worktree at ../{repository-name}-{branch-name}
  2. Checkout the specified branch (or create tracking branch for remote)
  3. Change to the new worktree directory
  4. Optionally copy untracked .env files from the original repository
  5. Automatically run package manager setup if detected

Remove a worktree

# Remove specific worktree
gw end 123

# Interactive mode - select from list
gw end

# Force removal without safety checks
gw end 123 --force

Safety checks include:

  • Uncommitted changes
  • Unpushed commits
  • Merge status with origin/main

Configuration

Future versions will support configuration via .gwconfig file for:

  • Default base branch
  • Custom worktree location
  • Package manager preferences

Development

Project Structure

gw/
├── cmd/               # Command implementations
├── internal/
│   ├── git/          # Git operations
│   ├── detect/       # Package manager detection
│   ├── ui/           # Interactive UI components
│   └── config/       # Configuration management
├── main.go
└── go.mod

Building

go build -o gw

Testing

go test ./...

License

MIT

About

Git worktree manager

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages