git-worktree-agent
v0.2.4
Published
A TUI for managing git worktrees from remote branches with automatic polling and hooks
Maintainers
Readme
git-worktree-agent (gwa)
A terminal UI for managing git worktrees from remote branches with automatic polling and configurable hooks.

Installation
Via npm (recommended)
The easiest way to install gwa is via npm. This works on Linux, macOS, and Windows:
npm install -g git-worktree-agentAfter installation, the gwa command will be available globally:
gwa --versionVia npx (no install)
You can also run gwa directly without installing:
npx git-worktree-agentVia Cargo
If you have Rust installed, you can install via Cargo:
cargo install git-worktree-agentFrom Source
git clone https://github.com/peterbartels/git-worktree-agent
cd git-worktree-agent
cargo install --path .Download Binary
Pre-built binaries are available on the GitHub Releases page for:
- Linux (x64, arm64)
- macOS (x64, Apple Silicon)
- Windows (x64)
Features
- 🔄 Automatic Branch Watching: Polls remote for new branches every 10 seconds (configurable)
- 🌳 Smart Worktree Creation: Automatically creates local worktrees for remote branches
- ⚡ Post-Create Hooks: Run commands like
npm installautomatically when worktrees are created - 📋 Track/Untrack Branches: Fine-grained control over which branches to manage
- 🎯 Pattern-Based Filtering: Ignore branches matching glob patterns
- 💾 Persistent Configuration: JSON config file (gitignored for per-user settings)
- 🖥️ Beautiful TUI: Built with ratatui for a modern terminal experience
Quick Start
Navigate to your git repository:
cd /path/to/your/repoInitialize the configuration:
gwa --initStart the TUI:
gwaOn first run, you'll be prompted to select which branches to create worktrees for.
Usage
TUI Mode (default)
gwa # Start in current directory
gwa --path /path/to/repo # Start in specific directory
gwa --debug # Enable debug loggingKeyboard Shortcuts
| Key | Action |
|-----|--------|
| j / ↓ | Move down |
| k / ↑ | Move up |
| Enter | Create worktree for selected branch |
| d | Delete/untrack worktree |
| t | Toggle track/untrack branch |
| r | Refresh (fetch from remote) |
| a | Toggle auto-create mode |
| l | View full command logs |
| ? | Show help |
| q / Esc | Quit |
Command Line Options
# Show current configuration
gwa --show-config
# Set post-create command
gwa --set-command "npm install"
# Set poll interval (in seconds)
gwa --set-poll-interval 30
# Enable auto-create mode
gwa --auto-create
# Initialize configuration interactively
gwa --initConfiguration
The configuration is stored in .gwa-config.json in your repository root. This file is automatically added to .gitignore since settings are typically per-developer.
Example Configuration
{
"version": 1,
"poll_interval_secs": 10,
"post_create_command": "npm install",
"command_working_dir": null,
"ignore_patterns": [
"dependabot/*",
"renovate/*"
],
"tracked_branches": [
"feature/my-feature",
"fix/important-bug"
],
"untracked_branches": [
"main",
"develop"
],
"auto_create_worktrees": false,
"worktree_base_dir": "..",
"remote_name": "origin",
"worktrees": []
}Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| poll_interval_secs | number | 10 | How often to check for new branches (seconds) |
| post_create_command | string | null | Command to run after creating a worktree |
| command_working_dir | string | null | Subdirectory to run commands in (relative to worktree root) |
| ignore_patterns | array | [] | Glob patterns for branches to ignore |
| tracked_branches | array | [] | Branches to explicitly track |
| untracked_branches | array | [] | Branches to explicitly ignore |
| auto_create_worktrees | boolean | false | Automatically create worktrees for new branches |
| worktree_base_dir | string | ".." | Where to create worktrees (relative to repo root) |
| remote_name | string | "origin" | Remote to watch |
How It Works
- Discovery: GWA discovers the git repository from your current directory
- Polling: Every N seconds, it fetches from the configured remote
- Detection: New branches are detected by comparing with known branches
- Creation: Worktrees are created in the configured base directory
- Hooks: If configured, post-create commands are run automatically
Worktree Layout
By default, worktrees are created in the parent directory of your repository:
projects/
├── my-repo/ # Main repository (where you run gwa)
│ ├── .git/
│ ├── .gwa-config.json
│ └── ...
├── feature-my-feature/ # Worktree for feature/my-feature
├── fix-important-bug/ # Worktree for fix/important-bug
└── ...Development
Prerequisites
- Rust 1.70 or later
- Git
Building
# Debug build
cargo build
# Release build
cargo build --release
# Run directly
cargo run
# Run with debug logging
cargo run -- --debugTesting
# Run tests
cargo test
# Run tests with output
cargo test -- --nocaptureProject Structure
src/
├── main.rs # Entry point and CLI handling
├── app.rs # Main application state and TUI logic
├── config.rs # Configuration management
├── executor.rs # Command execution for hooks
├── watcher.rs # Remote branch polling
├── git/
│ ├── mod.rs
│ ├── repository.rs # Git repository operations
│ └── worktree.rs # Worktree management
└── ui/
├── mod.rs
├── branch_list.rs # Branch list widget
├── status.rs # Status bar widget
├── logs.rs # Command logs widget
└── help.rs # Help overlay widgetArchitecture
- gitoxide (gix): Used for git operations (fetching, reading refs)
- git CLI: Used for worktree operations (create, remove, list)
- ratatui: TUI framework for the terminal interface
- crossterm: Terminal handling (events, rendering)
Building for Release
The project includes scripts for building release binaries:
# Install cross for cross-compilation
cargo install cross
# Build for all platforms
./scripts/build-release.shTroubleshooting
"Failed to discover git repository"
Make sure you're running gwa from within a git repository or specify the path:
gwa --path /path/to/repo"Fetch failed"
Check your network connection and ensure you have access to the remote repository:
git fetch originWorktree creation fails
Ensure the target directory doesn't exist and you have write permissions:
ls -la ../ # Check parent directoryHooks not running
Check the command is valid and the working directory exists:
gwa --show-config # Verify configurationContributing
Contributions are welcome! Please feel free to submit issues and pull requests.
See DEPLOYMENT.md for information on how releases are managed.
License
MIT License - see LICENSE for details.
Related Projects
- git-worktree - Git's built-in worktree command
- gitoxide - Rust implementation of Git
- ratatui - Rust TUI library
