| name | git |
| description | Git workflow helper. Use for committing changes, creating branches, viewing history, stashing work, resolving merge conflicts, and other git operations. Invoke when the user asks to commit, push, branch, stash, or do any git-related task.
|
| allowed-tools | bash read |
Git
Git workflow helper. Follow the instructions for the relevant operation.
Commit
When the user wants to commit changes:
1. Understand the changes
Run all of these:
git status
git diff --cached
git diff
git log --oneline -5
2. Analyze
- What type of change is this? (feat / fix / refactor / docs / test / chore)
- What is the primary purpose? Focus on WHY, not WHAT.
- Does the project use Conventional Commits? Check the recent git log output.
- Are there any breaking changes?
3. Stage files if needed
If git diff --cached is empty but git diff shows changes, stage the relevant files:
git add <specific-files>
IMPORTANT: Do NOT run git add -A or git add . unless the user explicitly asked for all files. Stage specific files by name.
Do NOT stage files that look like secrets (.env, credentials.json, *.pem, etc.). Warn the user if you see them.
4. Draft the commit message
Rules:
- First line: 50 characters or fewer
- Use imperative mood: "add feature" not "added feature"
- Body (if needed): explain WHY, separated by blank line
- No period at end of subject line
- Match the style from git log output
If the project uses Conventional Commits:
<type>(<scope>): <short description>
5. Create the commit
git commit -m "<message>"
For multi-line messages, use heredoc:
git commit -m "$(cat <<'EOF'
<subject line>
<body>
EOF
)"
6. Verify
git log --oneline -1
Report what was committed.
Branch
When the user wants to create or switch branches:
Create and switch to a new branch
git checkout -b <branch-name>
Switch to an existing branch
git checkout <branch-name>
List branches
git branch -a
Delete a branch
git branch -d <branch-name>
Use -D only if the user explicitly asks to force-delete.
Stash
When the user wants to save work temporarily:
Stash current changes
git stash push -m "<description>"
List stashes
git stash list
Apply most recent stash
git stash pop
Apply a specific stash
git stash apply stash@{<n>}
History
When the user wants to see git history:
Recent commits
git log --oneline -20
Detailed log for a file
git log --oneline -10 -- <file>
Show a specific commit
git show <commit-hash>
Who changed a line
git blame <file>
Merge conflicts
When the user needs to resolve merge conflicts:
1. See what's conflicted
git status
2. Read each conflicted file
Use read on each file listed as "both modified" to see the conflict markers.
3. Resolve
Edit each file to remove conflict markers (<<<<<<<, =======, >>>>>>>) and keep the correct code.
4. Mark resolved and continue
git add <resolved-files>
git merge --continue
Or if rebasing:
git add <resolved-files>
git rebase --continue
Push
When the user wants to push:
git push
If the branch has no upstream:
git push -u origin <branch-name>
IMPORTANT: Never force-push unless the user explicitly asks for it. If push is rejected, tell the user and suggest git pull --rebase first.
Safety rules
- Never run
git reset --hard, git clean -f, or git push --force unless the user explicitly asks
- Never delete branches without asking
- Always show
git status before destructive operations
- Warn about uncommitted changes before switching branches
- Never commit .env, credentials, keys, or secrets