A Git worktree resource synchronization tool that automatically syncs resources like node_modules, .env files, and other dependencies when creating new worktrees.
- 🚀 Automatic Resource Sync: Automatically sync resources from your main worktree when creating new ones
- 🔗 Flexible Sync Modes: Choose between symlink (default) or copy mode
- ⚙️ Project-Aware: Auto-detects project type (Node.js, Rails, Go, Rust) and suggests appropriate templates
- 📝 Simple Configuration: Use
.gwt.ymlto define which resources to sync - 📊 Status Tracking: View all worktrees and their sync status
go install github.com/fs0414/git-worktree-sync/cmd/gws@latestgit clone https://github.com/fs0414/git-worktree-sync.git
cd git-worktree-sync
go build -o gws ./cmd/gws
sudo mv gws /usr/local/bin/- Initialize configuration in your project:
gws initThis creates a .gwt.yml file with default settings based on your project type.
- Create a new worktree with resource sync:
gws create feature-branchThis creates a new worktree and automatically syncs configured resources.
- List all worktrees and their sync status:
gws list- Sync resources to an existing worktree:
gws sync /path/to/worktreeInitialize a .gwt.yml configuration file in your project.
gws init # Auto-detect project type
gws init -t node # Use Node.js template
gws init -t rails # Use Rails template
gws init -t go # Use Go template
gws init -t rust # Use Rust template
gws init --force # Overwrite existing configCreate a new git worktree with resource synchronization.
gws create feature-branch # Create in default location
gws create feature-branch -p /path/to/dir # Specify custom path
gws create feature-branch --copy # Use copy instead of symlink
gws create feature-branch -b main # Create from main branch
gws create feature-branch --no-sync # Skip resource syncList all worktrees and their sync status.
gws list # Show all worktrees
gws list -v # Verbose mode with detailsSynchronize resources to an existing worktree.
gws sync # Sync current directory
gws sync /path/to/worktree # Sync specific worktree
gws sync --copy # Use copy mode
gws sync --force # Overwrite existing resourcesCreate a .gwt.yml file in your project root:
# Resources to sync via symlink
resources:
symlink:
- node_modules
- .pnpm-store
- dist
# Resources to copy
copy:
- .env
- .env.local
- .env.development
# Worktree path template ({branch} is replaced with branch name)
worktree_path: "../{branch}"
# Exclude patterns (glob supported)
exclude:
- "*.log"
- "tmp/*"gws includes built-in templates for common project types:
resources:
symlink:
- node_modules
- .pnpm-store
- dist
copy:
- .env
- .env.localresources:
symlink:
- vendor
- node_modules
- tmp
copy:
- .env
- config/master.keyresources:
symlink:
- vendor
copy:
- .envresources:
symlink:
- target
copy:
- .env# Initialize config if not already done
gws init
# Create new worktree
gws create feature-auth
# ✓ Created worktree at ../feature-auth
# ✓ Linked node_modules
# ✓ Copied .env
# ✨ Done! Run: cd ../feature-auth
cd ../feature-authgws create feature-a
gws create feature-b
gws create bugfix-123
gws list
# 📂 Worktrees for repository: my-project
#
# main /Users/user/dev/my-project (main worktree)
# ✓ feature-a /Users/user/dev/feature-a (synced)
# ✓ feature-b /Users/user/dev/feature-b (synced)
# ✓ bugfix-123 /Users/user/dev/bugfix-123 (synced)# Add new resource to .gwt.yml
echo " - build" >> .gwt.yml
# Sync to existing worktree
gws sync ../feature-branch
# 🔄 Syncing from main worktree: /path/to/main
# ✓ Linked build
# ✨ Sync complete!When working with git worktrees, you often need to recreate your development environment (install dependencies, copy config files, etc.) for each worktree. gws automates this process by:
- Saving time: No need to manually copy or symlink resources
- Reducing disk usage: Symlink large directories like
node_modulesinstead of duplicating them - Maintaining consistency: Ensure all worktrees have the same resources
- Simplifying workflow: One command to create a fully-configured worktree
git worktree add ../feature-branch
cd ../feature-branch
npm install # Time-consuming, uses disk space
cp ../ main/.env .
cp ../main/.env.local .
# ... repeat for each resourcegws create feature-branch
# Done! Everything is synced automatically- Git 2.5+ (for worktree support)
- Go 1.24+ (for building from source)
If you see "No .gwt.yml found", run gws init to create a configuration file.
On Windows, you may need administrator privileges to create symlinks. Alternatively, use --copy flag:
gws create feature-branch --copyIf a resource specified in .gwt.yml doesn't exist in the main worktree, it will be skipped with a warning.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
Created by fs0414