Create, switch, and manage git branches with proper handling of uncommitted changes. Use when creating feature branches, switching contexts, or cleaning up after merges.
Check Repository State
Invoke the git-state-validator skill to verify:
Handle Uncommitted Changes If changes exist, ask user:
git stash push -m "WIP: switching to new branch"Ensure Latest Default Branch
Invoke the git-sync skill to pull the latest changes from the default branch.
Determine Branch Prefix Based on work type:
feat/ - New featuresfix/ - Bug fixeschore/ - Maintenance, toolingdocs/ - Documentationrefactor/ - Code refactoringtest/ - Test additions/fixesperf/ - Performance improvementsCreate Branch
git checkout -b <prefix>/<description>
Branch name format:
feat/add-user-authenticationCheck Repository State
Invoke the git-state-validator skill to verify:
Handle Changes (if any)
git stash push -m "WIP: switching from <current> to <target>"Switch Branch
git checkout <branch-name>
Restore Stash (if applicable) After switching, if user stashed:
git stash list
git stash pop
Verify Branch is Merged
git branch --merged main
Switch to Main (if on the branch being deleted)
git checkout main
Check Branch Exists Before Deletion
git branch --list <branch-name>
If no output, branch doesn't exist - skip deletion
Delete Local Branch (only if exists)
git branch -d <branch-name>
Use -D (force delete) only if user explicitly confirms:
git branch -D <branch-name>
Verify Deletion
git branch --list <branch-name>
CRITICAL: Always check if branch exists before attempting deletion to avoid errors.
Safe Deletion Pattern:
# Check if branch exists
if git branch --list <branch-name> | grep -q <branch-name>; then
git branch -d <branch-name>
echo "Branch deleted"
else
echo "Branch does not exist, skipping"
fi
Why This Matters:
Good Examples:
feat/user-profile-pagefix/login-validation-errorchore/update-dependenciesdocs/api-endpoint-guideBad Examples:
my-branch (no type prefix)feat/ThisIsMyNewFeature (not kebab-case)feat/add-the-new-user-profile-page-with-authentication-and-settings (too long)Branch Already Exists: Ask user to:
git checkout <branch-name>git branch -D <branch-name> && git checkout -b <branch-name>Uncommitted Changes Conflict: