Git Workflow
Assist with common git operations: branching, staging, committing, pushing, and preparing pull requests. Always show commands before running them and require confirmation for destructive operations.
Covered Operations
- Branch management: create, switch, list, delete branches
- Staging and committing: stage changes, write commit messages, commit
- Pushing: push to remote, set upstream tracking
- Pull requests: prepare PR title and body from commit history
- Status checks: show working tree status, diff, and log
Procedure by Operation
Creating a Branch
- Check current branch:
git branch --show-current - Ensure working tree is clean or changes are stashed.
- Show command:
git checkout -b <branch-name> - Run after confirmation.
- Confirm the new branch is active.
Staging and Committing
- Show status:
git status - Show diff:
git diff --stat - Present specific files to stage (prefer explicit files over
git add .). - Show stage command and confirm.
- Run
git statusagain to verify staged set. - Draft a commit message following Conventional Commits format:
<type>(<scope>): <summary>where type is feat/fix/docs/refactor/test/chore. - Show the full commit command with the message.
- Commit after confirmation.
Pushing
- Check if remote tracking branch exists:
git rev-parse --abbrev-ref @{u} - If no upstream: show
git push -u origin <branch>and confirm. - If upstream exists: show
git pushand confirm. - Never push with
--forcewithout explicit instruction.
Preparing a Pull Request
- Get the base branch (usually
mainormaster):git branch -r - Show commits on this branch:
git log origin/main..HEAD --oneline - Show diff summary:
git diff origin/main...HEAD --stat - Draft PR title (≤70 chars) from the commit messages.
- Draft PR body with sections: Summary (bullet points), Testing, Notes.
- Output the
gh pr createcommand for review.
Output Format
## Git Operation: <operation name>
Command: `<exact git command>`
<output of command>
Status: <success / confirmation needed / error>
Next step: <what to do next>
Quality Rules
- Always show the command before running it.
- Never run
git reset --hard,git push --force,git clean -f, orgit checkout -- .without explicit user instruction. - For destructive operations, describe exactly what will be lost before asking for confirmation.
- Prefer
git restore --staged <file>overgit reset HEAD <file>for unstaging. - Write commit messages that explain why, not just what.
Source: mattmre/AGENT33-PUBLIC — distributed by TomeVault.