| name | git |
| description | Git operations including commits, branches, worktrees, and safety protocols. Use on 'git', 'commit', 'branch', 'worktree', 'rebase', 'merge'. |
Git Skill
Safe, consistent git operations for agents.
Safety Protocol (CRITICAL)
These rules are NON-NEGOTIABLE:
- Never amend pushed commits - verify with
git status showing "Your branch is ahead"
- Never force push to main/master - warn user if requested
- Never skip hooks - no
--no-verify or --no-gpg-sign
- Never commit secrets - reject
.env, credentials.json, *.key, *.pem
- Never push automatically - leave pushing to the user. This includes
git push AND gh pr create. Creating PRs is equivalent to pushing.
- Always verify branch state before destructive operations
Conventional Commits
Format: <type>(<scope>): <description>
| Type | When to Use |
|---|
feat | New feature |
fix | Bug fix |
docs | Documentation only |
style | Formatting, no code change |
refactor | Code change, no feature/fix |
perf | Performance improvement |
test | Adding/fixing tests |
chore | Build, tooling, deps |
ci | CI/CD changes |
revert | Reverting previous commit |
Rules:
- Imperative mood, present tense ("add" not "added")
- First line under 72 characters
- Scope is optional but helpful:
feat(auth): add login endpoint
- Focus on "why" not "what"
Workflow: Making a Commit
git status
git diff
git diff --cached
git add <specific-files>
git commit -m "type(scope): description"
git log -1
git status
Workflow: Branching
git branch --show-current
git checkout -b feat/short-description
git checkout -b fix/bug-description main
Branch naming conventions:
feat/ - new features
fix/ - bug fixes
chore/ - maintenance
refactor/ - code restructuring
docs/ - documentation
Rebase vs Merge
Context-dependent - choose based on situation:
| Use Rebase | Use Merge |
|---|
| Cleaning local commits before PR | Preserving branch history |
| Linear history preferred | Shared branch with others |
| Feature branch behind main | Main into feature (public branch) |
NEVER rebase pushed commits unless user explicitly requests it (requires force push).
Danger Zone Checklist
Before ANY destructive operation (reset --hard, push --force, rebase -i, commit --amend):
If ANY checkbox is unclear, ask the user first.
Worktree Patterns
Convention: worktrees go in ./tree/ directory.
git worktree list
git worktree add ./tree/feat-branch feat-branch
git worktree add -b fix/new-fix ./tree/fix-new-fix main
git worktree remove ./tree/old-branch
git worktree prune
Amend Rules
Only use git commit --amend when ALL conditions are met:
- User explicitly requested amend, OR commit succeeded but pre-commit hook auto-modified files
- HEAD commit was created by you in this session (verify:
git log -1 --format='%an %ae')
- Commit has NOT been pushed to remote (verify:
git status shows "Your branch is ahead")
If commit FAILED or was REJECTED by hook - NEVER amend. Fix the issue and create a NEW commit.
Quick Reference
git status
git log --oneline -10
git diff HEAD~1
git reset --soft HEAD~1
git checkout -- <file>
git stash
git stash pop
git fetch --dry-run
git log origin/main..HEAD