Git Worktree Follow Mode Specification
Overview
Follow mode is a feature that enables automatic synchronization between Git worktrees and the main repository. It ensures team members stay on the same branch by automatically switching branches when changes are detected.Core Concept
Follow mode creates a unidirectional sync from a worktree to the main repository:- When someone switches branches in a worktree
- The main repository automatically follows that branch change
- This keeps the main repository synchronized with active development
When Follow Mode Should Be Available
✅ Follow Mode SHOULD appear when:
-
Creating a session in a worktree
- You’ve selected a worktree from the dropdown
- The session will run in that worktree’s directory
- Follow mode will sync the main repository to match this worktree’s branch
-
Viewing worktrees in the Worktree Manager
- Each worktree (except main) shows a “Follow” button
- Enables following that specific worktree’s branch
-
Session list with worktree sessions
- Repository headers show follow mode status
- Dropdown allows changing which worktree to follow
❌ Follow Mode should NOT appear when:
-
No worktree is selected (using main repository)
- There’s nothing to follow - you’re already in the main repo
- Follow mode has no purpose without a worktree
-
Repository has no worktrees
- No worktrees exist to follow
- Only the main repository is available
-
Not in a Git repository
- Obviously, no Git features available
UI Behavior Rules
Session Creation Form
Toggle States:
-
Worktree Selected:
- Show: “Follow Mode” toggle
- Description: “Keep main repository in sync with this worktree”
- Default: OFF (user must explicitly enable)
-
No Worktree Selected:
- Hide the entire follow mode section
- No toggle should be visible
-
Follow Mode Already Active:
- Show: “Follow Mode” toggle (disabled)
- Description: “Currently following: [branch-name]”
- Info: User must disable from worktree manager
Worktree Manager
Each worktree row shows:- “Follow” button: When not currently following
- “Following” button (green): When actively following this worktree
- No button: For the main worktree (can’t follow itself)
Session List
Repository headers show:- Purple badge: When follow mode is active, shows branch name
- Dropdown: To change follow mode settings per repository
Technical Implementation
State Logic
Configuration Storage
Follow mode state is stored in Git config:Synchronization Rules
-
Automatic Sync:
- Triggered by
post-checkout
git hook in worktrees - Only syncs if main repo has no uncommitted changes
- Disables follow mode if branches have diverged
- Triggered by
-
Manual Override:
- Users can always manually switch branches
- Follow mode doesn’t prevent manual git operations
- Re-enables when returning to the followed branch
User Experience Guidelines
Clear Messaging
-
When Enabling:
- “Follow mode will keep your main repository on the same branch as this worktree”
- “Enable to automatically sync branch changes”
-
When Active:
- “Following worktree: feature/new-ui”
- “Main repository syncs with this worktree’s branch”
-
When Disabled:
- “Follow mode disabled due to uncommitted changes”
- “Branches have diverged - follow mode disabled”
Visual Indicators
- Toggle Switch: Only visible when applicable
- Status Badge: Purple badge with branch name when active
- Button States: Clear “Follow”/“Following” states in worktree manager
Error Handling
Common Scenarios
-
Uncommitted Changes:
- Disable follow mode automatically
- Show notification to user
- Don’t lose any work
-
Branch Divergence:
- Detect when branches have different commits
- Disable follow mode to prevent conflicts
- Notify user of the situation
-
Worktree Deletion:
- Automatically disable follow mode
- Clean up git config
- Update UI immediately
Summary
Follow mode should be:- Contextual: Only shown when it makes sense
- Safe: Never causes data loss or conflicts
- Clear: Users understand what it does
- Automatic: Works in the background when enabled