+
Skip to content

sotarok/gw

Repository files navigation

gw - Git Worktree CLI Tool

CI Release codecov 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, composer)
  • 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)
  • iTerm2 tab name integration - automatically update tab names when switching worktrees
  • 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

Initialize configuration

# Run interactive configuration setup
gw init

# View and edit configuration interactively
gw config

# List configuration values (non-interactive)
gw config --list

The gw init command creates a ~/.gwrc file with your preferences through an interactive setup. The gw config command allows you to view and modify your configuration at any time.

Create a new worktree

# Create worktree for issue #123 (creates branch "123/impl")
gw start 123

# Create worktree with custom branch name
gw start 476/impl-migration-script

# Create worktree for feature branch
gw start feature/new-feature

# Create worktree based on specific base 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}-{identifier}
  2. Create a new branch (either {issue-number}/impl for numbers, or the exact branch name provided)
  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

The gw tool can be configured via ~/.gwrc file. Use gw init for initial setup or gw config to modify settings at any time.

Managing Configuration

# Interactive configuration editor (TUI)
gw config

# List current configuration
gw config --list

The interactive config editor allows you to:

  • Navigate settings with arrow keys or j/k
  • Toggle boolean values with Enter or Space
  • Save changes with 's'
  • Quit with 'q'
  • View help with '?'

Configuration Options

  • auto_cd: Automatically change to the new worktree directory after creation (default: true)
  • update_iterm2_tab: Update iTerm2 tab name when creating/switching/removing worktrees (default: false)

Example ~/.gwrc:

# gw configuration file
auto_cd = true
update_iterm2_tab = false

iTerm2 Tab Integration

When update_iterm2_tab is enabled and you're using iTerm2:

  • Tab name is updated to "{repository-name} {issue-number/branch-name}" when creating or switching worktrees
  • Tab name is reset when removing worktrees
  • Only works when running in iTerm2 terminal (automatically detected)

Shell Integration

To enable automatic directory changing after creating worktrees, you need to set up shell integration:

Quick Setup

Add one of these lines to your shell configuration file:

# For Bash (~/.bashrc)
eval "$(gw shell-integration --show-script --shell=bash)"

# For Zsh (~/.zshrc)
eval "$(gw shell-integration --show-script --shell=zsh)"

# For Fish (~/.config/fish/config.fish)
gw shell-integration --show-script --shell=fish | source

This method ensures you always have the latest shell integration code. See SHELL_INTEGRATION.md for more details.

Future Configuration Options

Future versions will support additional configuration:

  • 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
│   └── iterm2/       # iTerm2 integration
├── main.go
└── go.mod

Building

go build -o gw

Testing

# Run tests
go test ./...

# Run tests with coverage
make test

# Generate coverage report
make coverage

# View coverage in terminal
make coverage-report

License

MIT

About

Git worktree manager

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载