Skip to content

CLI tool to sync gitignored config files between git worktrees

Notifications You must be signed in to change notification settings

Frosco/worktree-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worktree-sync

Sync gitignored config files between git worktrees.

When using git worktrees, gitignored files (like .claude/, .vscode/, .env) don't transfer to new worktrees. This tool syncs them.

Installation

go build -o worktree-sync
cp worktree-sync ~/.local/bin/

Configuration

Create .worktree-sync.json in your repo root (add it to .gitignore):

{
  "paths": [".claude/", ".vscode/", ".env"],
  "exclude": [".vscode/settings.json"]
}

Paths ending in / are directories (all files synced recursively). Others are single files.

Global config

Create ~/.config/worktree-sync/config.json for paths you want synced in all projects:

{
  "paths": [".claude/"]
}

Project and global configs are merged. Project exclude can override global paths.

Usage

# After creating a new worktree
cd ../my-feature-branch
worktree-sync init      # Copy files from main

# Check what would be synced
worktree-sync status

# Manual sync (either direction)
worktree-sync pull      # Main -> worktree
worktree-sync push      # Worktree -> main

# Before removing a worktree
worktree-sync finish    # Sync back to main

Commands

Command Direction Description
init main → worktree Copy files to new worktree (skips existing)
pull main → worktree Update worktree from main (overwrites)
push worktree → main Push changes to main (prompts on conflicts)
finish worktree → main Same as push, with summary for cleanup
status Show what would be synced

Conflict handling

On push/finish, if a file was modified in both main and worktree since last sync, you'll be prompted:

Conflict: .claude/settings.json
Both main and worktree have been modified.
  [m] Use main version
  [w] Use worktree version
  [s] Skip (keep both as-is)
Choice:

How it works

  • Uses git worktree list to find the main worktree
  • Tracks sync state in .git/worktree-sync-state.json (per worktree)
  • Compares files by content, not just mtime
  • Creates directories as needed when copying

Development

# Install dev tools (goimports, golangci-lint)
make install-tools

# Install pre-commit hook
make install-hooks

# Format code
make fmt

# Run linter
make lint

# Run tests
make test

# Build
make build

About

CLI tool to sync gitignored config files between git worktrees

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •