tool-git
When To Use
- Inspect working tree state and commit history.
- Review and stage focused diffs before commit.
- Compare branches and verify what changed.
Trusted Commands
git status --short
git --no-pager diff
git --no-pager diff --staged
git --no-pager log --oneline -n 20
git --no-pager show HEAD
git add path/to/file
git restore --staged path/to/file
Safe Defaults
- Use
--no-pagerin non-interactive contexts. - Stage only task-relevant files.
- Check status before and after edits to avoid accidental scope creep.
Common Pitfalls
- Mixing unrelated edits into one commit.
- Using destructive reset/checkout patterns without explicit approval.
- Misreading staged vs unstaged columns in short status output.
Output Interpretation
??indicates untracked files.- Left/right
Mcolumns in short status represent index/worktree changes.
Why It Matters For Agents
- Git state determines safe automation and review boundaries.
- High-signal diff workflows prevent accidental regressions.
Commit Identity (per remote host)
Commits must carry the identity that matches the remote; set it per repo, not globally. Leaving the global
user.emailunset is deliberate — with no email git silently commits a…@hostname.localaddress, which pollutes and de-anonymizes history.Before committing, verify
git config user.emailis set for this repo; if empty or a.local/(none)hostname value, setgit config --local user.name/user.emailfirst.Automate it with git conditional includes so identity follows the remote URL:
# ~/.gitconfig (email is set only inside the includes; global email stays unset) [includeIf "hasconfig:remote.*.url:https://github.com/**"] path = ~/.gitconfig-github [includeIf "hasconfig:remote.*.url:https://git.example.com/**"] path = ~/.gitconfig-workScaffold this with
.scripts/setup_git_identity.py add --host <host> --name <n> --email <e>.Enforcement: the
identity-guardpre-commit hook blocks a commit whose identity is missing or auto-generated. Optionally require a domain per repo withgit config basicly.identityAllowEmail '@example\.com$'.
Repo Conventions
- Never rewrite history or run destructive git commands without explicit confirmation.
- Keep diffs minimal and avoid unrelated reformatting.
Trigger Examples
- Should trigger: "Review my staged diff for regressions before commit."
- Should trigger: "Show what changed in this branch compared to main."
- Should not trigger: "Lint this shell script for POSIX issues."