switch-feature

michael-menard's avatarfrom michael-menard

Commit or stash current work, then switch to another existing worktree. Use when switching between features or stories, ensures changes are saved before switching.

⭐0stars🔀0forks📁View on GitHub🕐Updated Dec 28, 2025

When & Why to Use This Skill

The switch-feature Claude skill optimizes Git workflows by automating the transition between different worktrees. It enhances developer productivity by ensuring uncommitted changes are safely stashed or committed before providing clear navigation instructions to another feature or bug fix branch, preventing data loss and streamlining context switching during complex software development cycles.

Use Cases

  • Rapid Context Switching: Seamlessly move between multiple active features or stories by stashing current progress and jumping to a different worktree without manual git status checks.
  • Safe Workspace Transition: Prevent accidental data loss by using guided prompts to commit, stash, or discard changes before switching development environments.
  • Efficient Worktree Management: Quickly visualize all active Git worktrees and receive the exact shell commands needed to navigate to the correct directory and open a new terminal session.
nameswitch-feature
descriptionCommit or stash current work, then switch to another existing worktree. Use when switching between features or stories, ensures changes are saved before switching.

/switch-feature - Commit and Switch to Another Worktree

Description

Commits or stashes current work, then helps you switch to another existing worktree.

Usage

/switch-feature

What It Does

Step 1: Check Git Status

git status --porcelain

Step 2: Handle Uncommitted Changes

If there are uncommitted changes:

Ask user:

⚠️  You have uncommitted changes. What would you like to do?

1. Commit changes
2. Stash changes
3. Discard changes (dangerous!)
4. Cancel

Option 1: Commit Changes

# Show current changes
git status

# Ask for commit message
git add -A
git commit -m "{user_message}"
git push origin HEAD

Option 2: Stash Changes

# Stash with message
git stash push -m "{user_message}"

Option 3: Discard Changes

# Warn and confirm
git reset --hard HEAD
git clean -fd

Option 4: Cancel

❌ Operation cancelled.

Step 3: List Available Worktrees

git worktree list

Display to user:

Available worktrees:

1. /Users/user/project (main) [main branch]
2. /Users/user/project/tree/feature/gallery-123 [feature/gallery-123]
3. /Users/user/project/tree/bug/main-app-456 [bug/main-app-456]
4. /Users/user/project/tree/feature/auth-567 [feature/auth-567]

Which worktree would you like to switch to? (1-4)

Step 4: Provide Switch Instructions

After user selects worktree #2:

✅ To switch to feature/gallery-123:

cd tree/feature/gallery-123

Or use this command to switch and open in new terminal:
cd tree/feature/gallery-123 && exec $SHELL

Your current changes have been committed/stashed safely.

Benefits

✅ Safe Switching - Never lose uncommitted work ✅ Quick Navigation - See all worktrees at a glance ✅ Clean Transitions - Proper commit/stash before switching ✅ Simple - One command to handle everything

Notes

  • This is a slash command (one-shot operation)
  • It doesn't actually change your terminal's directory (can't do that)
  • Instead, it provides the cd command for you to run
  • Your changes are safely committed or stashed before switching