skills/git-workflows/skills/switch/SKILL.md
Switch branches safely with uncommitted change handling
npx skillsauth add dtsong/my-claude-setup Git SwitchInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
--create flag is used.., shell metacharacters, or null bytes. The special value - (previous branch) is also accepted.Switch to a different branch with smart handling of uncommitted changes.
/git-switch main # Switch to main
/git-switch feat/dark-mode # Switch to feature branch
/git-switch - # Switch to previous branch
/git-switch --create feat/new # Create and switch
# Check for both staged and unstaged changes
HAS_CHANGES=false
if ! git diff --quiet || ! git diff --cached --quiet; then
HAS_CHANGES=true
fi
# Also check for untracked files
UNTRACKED=$(git ls-files --others --exclude-standard | wc -l)
If changes exist, present options:
if [ "$HAS_CHANGES" = true ]; then
echo "You have uncommitted changes:"
git status --short
# Options presented to user via AskUserQuestion:
# 1. Stash and switch (will restore after)
# 2. Carry changes to new branch
# 3. Discard changes and switch
# 4. Cancel
fi
TARGET_BRANCH="$1"
# Check local
if git show-ref --verify --quiet "refs/heads/$TARGET_BRANCH"; then
echo "Switching to local branch: $TARGET_BRANCH"
# Check remote
elif git show-ref --verify --quiet "refs/remotes/origin/$TARGET_BRANCH"; then
echo "Creating local tracking branch from origin/$TARGET_BRANCH"
git checkout -b "$TARGET_BRANCH" "origin/$TARGET_BRANCH"
exit 0
else
echo "Branch '$TARGET_BRANCH' not found locally or on origin."
echo "Did you mean to create it? Use: /git-branch $TARGET_BRANCH"
exit 1
fi
# Standard switch
git switch "$TARGET_BRANCH"
# Or if carrying changes
git switch "$TARGET_BRANCH" # Changes come along if no conflict
# Previous branch shortcut
git switch -
# Show where we are now
git status -sb
# If we stashed, offer to restore
if [ "$DID_STASH" = true ]; then
echo "Stashed changes are available. Restore with: /git-stash pop"
fi
Switched to branch: feat/dark-mode
Branch status:
Tracking: origin/feat/dark-mode
Behind: 0 commits
Ahead: 2 commits
Recent commits on this branch:
abc1234 Add theme toggle
def5678 Wire up context
Uncommitted changes detected:
M src/components/Header.tsx
A src/styles/new.css
Changes stashed automatically.
Switched to branch: main
To restore your changes:
/git-stash pop
Or keep them stashed:
/git-stash list
Switched to branch: feat/dark-mode
Uncommitted changes carried over:
M src/components/Header.tsx
These changes are now on feat/dark-mode (not committed).
Cannot switch to main!
Your local changes to these files would be overwritten:
- src/components/Header.tsx
Options:
/git-stash # Stash changes first
/commit # Commit changes first
git checkout -- <file> # Discard specific changes
| Command | Description |
|---------|-------------|
| /git-switch - | Switch to previous branch |
| /git-switch main | Switch to main branch |
| /git-switch --create name | Create new branch and switch |
When branch name is partial or ambiguous, show matches:
Multiple branches match 'feat/':
feat/dark-mode
feat/user-auth
feat/api-v2
Specify full name to switch.
/git-branches to see all available branches/git-stash for manual stash control/git-branch to create new branches/git-sync after switching to check for updatesdevelopment
Use when planning implementation steps, deciding commit format, or structuring development approach. Provides brainstorm-plan-implement flow with conventional commits. Triggers on 'how should I approach this', 'commit format'.
development
Security audit checklist for web applications. Use when reviewing, auditing, or hardening a web app's security posture. Covers rate limiting, auth headers, IP blocking, CORS, security middleware, input validation, file upload limits, ORM usage, and password hashing. Triggers on requests like "review security", "harden this app", "security audit", "check for vulnerabilities", or when building/reviewing API endpoints.
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
development
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.