| name | git-expert |
| description | Use when working with git operations including commits, branches, worktrees, and PRs. Covers the full git workflow from feature isolation to PR submission. |
Git Expert
Overview
Expert git workflow skill covering isolation (worktrees), commits, branching, and PR submission using GitHub CLI (gh).
Core principles:
- Isolation: Work in worktrees to avoid context pollution
- Atomic commits: Each commit represents one logical change
- Verification: Always verify before committing or pushing
- Clean history: Meaningful commits, clean rebases
Sub-Skills
This skill contains three sub-skills for different phases:
- Worktrees - Feature isolation and workspace setup
- Commits - Intelligent commit protocol
- Finishing - Branch completion and PR submission
1. Git Worktrees
When to Use
- Starting feature work that needs isolation
- Before executing implementation plans
- Working on multiple branches simultaneously
- Need clean baseline without affecting main workspace
Directory Selection Process
Follow this priority:
ls -d .worktrees 2>/dev/null
ls -d worktrees 2>/dev/null
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
Safety Verification
MUST verify directory is ignored before creating worktree:
git check-ignore -q .worktrees 2>/dev/null
If NOT ignored:
- Add to .gitignore:
echo '.worktrees/' >> .gitignore
- Commit the change
- Proceed with worktree creation
Creation Steps
project=$(basename "$(git rev-parse --show-toplevel)")
git worktree add .worktrees/$BRANCH_NAME -b feature/$BRANCH_NAME
cd .worktrees/$BRANCH_NAME
if [ -f package.json ]; then npm install; fi
if [ -f Cargo.toml ]; then cargo build; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f go.mod ]; then go mod download; fi
npm test
Worktree Commands
| Command | Purpose |
|---|
git worktree add <path> -b <branch> | Create new worktree with branch |
git worktree list | List all worktrees |
git worktree remove <path> | Remove worktree |
git worktree prune | Clean up stale references |
2. Git Commits
Core Rules
Never do without explicit permission:
- Push to remote
- Force push
- Run
git clean -fdx
- Modify git config
- Amend pushed commits
Always do:
- Include meaningful commit messages
- Check status before operations
- Verify tests pass before committing
- Use HEREDOC for multi-line messages
Pre-Commit Protocol
git status
npm run lint && npm run typecheck
npm test
git diff --cached
Commit Message Format
Format: {type}: {summary}
Types:
feat: New feature
fix: Bug fix
refactor: Code restructuring
docs: Documentation
style: Formatting
test: Tests
build: Build system
chore: Maintenance
Examples:
git commit -m "feat: add user profile endpoint"
git commit -m "fix: resolve race condition in auth flow"
git commit -m "refactor: extract validation helpers"
Multi-Line Commit Messages
Use HEREDOC for complex messages:
git commit -m "$(cat <<'EOF'
feat: implement retry mechanism for API calls
- Add exponential backoff with jitter
- Configure max retries via environment variable
- Add comprehensive test coverage
Closes #123
EOF
)"
Staged vs Unstaged
git diff --cached --name-only
git diff --name-only
git add src/auth/* tests/auth/*
git add -p
Verification Before Commit
MANDATORY before every commit:
npm test
npm run lint
npm run typecheck
git diff --cached
3. Finishing a Development Branch
When to Use
- Implementation complete
- All tests pass
- Ready to integrate work
The Process
Step 1: Verify Tests
npm test
If tests fail, stop. Fix before continuing.
Step 2: Determine Base Branch
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master
Step 3: Present Options
Implementation complete. What would you like to do?
1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work
Which option?
Option 1: Merge Locally
git checkout main
git pull
git merge feature/my-feature
npm test
git branch -d feature/my-feature
Then cleanup worktree.
Option 2: Create PR (Standard Git)
git push -u origin feature/my-feature
gh pr create --title "Add feature X" --body "$(cat <<'EOF'
## Summary
- Implemented X
- Added tests for Y
## Test Plan
- [ ] Unit tests pass
- [ ] Integration tests pass
EOF
)"
Option 3: Keep As-Is
Report status. Don't cleanup.
Option 4: Discard
Require confirmation:
This will permanently delete:
- Branch feature/my-feature
- All commits: abc123, def456
- Worktree at .worktrees/my-feature
Type 'discard' to confirm.
git checkout main
git branch -D feature/my-feature
git worktree remove .worktrees/my-feature
Branch Naming
| Type | Pattern | Example |
|---|
| Feature | feature/description | feature/user-auth |
| Bug fix | fix/description | fix/login-redirect |
| Refactor | refactor/description | refactor/auth-module |
| Personal | dev/name/description | dev/erik/auth-poc |
Protected Branches
main / master: Production (never direct push)
develop / dev: Development/staging
Always create feature branches from the appropriate base.
Common Mistakes
Skipping verification
- Problem: Commit broken code
- Fix: Always run tests before commit
Force push without warning
- Problem: Overwrite others' work
- Fix: Never force push without explicit permission
Worktree not ignored
- Problem: Worktree contents tracked in git
- Fix: Always verify
.worktrees/ is in .gitignore
Committing secrets
- Problem: Expose credentials
- Fix: Check for .env, credentials files before staging
Vague commit messages
- Problem: Unclear history
- Fix: Use type prefix, describe the "why"
Red Flags - STOP
Never:
- Push without explicit request
- Force push (especially to main/master)
- Commit without tests passing
- Delete branches without confirmation
- Proceed with failing tests
Always:
- Verify tests before commit
- Use meaningful commit messages
- Check what's staged before committing
- Get confirmation for destructive operations
Quick Reference
git worktree add .worktrees/feature -b feature/name
cd .worktrees/feature && npm install && npm test
git status
npm test && npm run lint
git add <files>
git commit -m "type: description"
git push -u origin feature/name
gh pr create
git worktree remove .worktrees/feature
git branch -d feature/name
Integration
On-demand loading: This is a Domain skill, loaded when git operations detected.
Pairs with:
- tdd - Tests pass before commits
- verification - Verify before PR submission
- subagent-driven-development - Feature branches for sub-agent work