| name | git-cli-agentic |
| description | Git commands with porcelain and machine-readable output for agent workflows. Use when scripting status/diff/log, porcelain=v2, --numstat counts, custom --format placeholders, or branch tracking info. |
| user-invocable | false |
| allowed-tools | Bash(git status *), Bash(git diff *), Bash(git log *), Bash(git branch *), Bash(git remote *), Bash(git add *), Bash(git commit *), Bash(git push *), Bash(git restore *), Read |
| created | "2025-01-16T00:00:00.000Z" |
| modified | "2026-06-18T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
Git CLI Agentic Patterns
When to Use This Skill
| Use this skill when... | Use the alternative when... |
|---|
Writing scriptable git status/diff/log calls in porcelain or --format mode | Use gh-cli-agentic for gh JSON queries against the GitHub API |
Needing --porcelain=v2 status, --numstat diff counts, or custom --format log placeholders | Use git-commit-workflow for staging conventions and commit message structure |
| Reading branch tracking info or main-branch-development push patterns | Use git-branch-pr-workflow for the broader branch + PR design choices |
| Producing deterministic output for parsers and downstream tooling | Use git-derive-docs to mine commit history for rules/PRDs/ADRs/PRPs |
Optimized git commands for AI agent consumption using porcelain output and stable formats.
Core Principle
Use --porcelain for machine-readable output that remains stable across Git versions and user configurations.
Working Directory
Run git commands directly — your working directory is the repo:
git status
git log --oneline -5
git diff --stat
The -C flag is only needed when targeting a different repository from your current directory:
git -C "$(git rev-parse --show-toplevel)" remote get-url origin
for repo in repos/*; do
git -C "$repo" status --porcelain
done
Status Operations
Porcelain Status
git status --porcelain=v2 --branch
git status --porcelain
git status --short --branch
Porcelain v2 Format:
# branch.oid <commit>
# branch.head <branch>
# branch.upstream <upstream>
# branch.ab +<ahead> -<behind>
1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>
2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path><tab><origPath>
? <path>
! <path>
Status Codes:
| Code | Meaning |
|---|
| M | Modified |
| A | Added |
| D | Deleted |
| R | Renamed |
| C | Copied |
| ? | Untracked |
| ! | Ignored |
Quick Checks
git status --porcelain
git status --porcelain | wc -l
git diff --quiet || echo "has changes"
Diff Operations
Stat Output
git diff --stat
git diff --numstat
git diff --name-status
git diff --name-only
Numstat Format: <added>\t<deleted>\t<filename>
Staged vs Unstaged
git diff --numstat
git diff --cached --numstat
git diff HEAD --numstat
Specific Comparisons
git diff $COMMIT --numstat
git diff main..feature --numstat
git diff $COMMIT1..$COMMIT2 --name-status
Log Operations
Custom Format
git log --format='%H %s' -n 10
git log --oneline -n 10
git log --oneline --stat -n 5
git log --format='%H|%an|%ae|%s' -n 10
Format Placeholders:
| Placeholder | Meaning |
|---|
%H | Full commit hash |
%h | Short hash |
%s | Subject |
%b | Body |
%an | Author name |
%ae | Author email |
%ad | Author date |
%cn | Committer name |
Filtering
git log --author="name" --oneline -n 10
git log --since="2025-01-01" --oneline
git log --oneline -n 10 -- path/to/file
git log --merges --oneline -n 5
Branch Operations
Branch Info
git branch -vv
git branch --format='%(refname:short) %(upstream:short) %(upstream:track)'
git branch --show-current
git branch -r --format='%(refname:short)'
Tracking Status
git rev-list --left-right --count origin/main...HEAD
Remote Operations
git remote -v
git remote get-url origin
git remote show origin
Staging Operations
git add path/to/file
git add -u
git add -A
git restore --staged path/to/file
git restore path/to/file
Commit Operations
git commit -m "message"
git commit -m "$(cat <<'EOF'
Subject line
Body paragraph with `code` and $vars written verbatim.
Co-Authored-By: Name <email>
EOF
)"
git commit --amend -m "new message"
Push Operations
git push origin HEAD
git push origin main:feature-branch
git push origin start^..end:feature-branch
git push -u origin HEAD
Agentic Optimizations
| Context | Command |
|---|
| Quick status | git status --porcelain=v2 --branch |
| Changed files | git diff --name-status |
| Staged changes | git diff --cached --numstat |
| Recent commits | git log --format='%h %s' -n 5 |
| Branch tracking | git branch -vv --format='%(refname:short) %(upstream:track)' |
| Current branch | git branch --show-current |
Error Handling in Context
Use 2>/dev/null to suppress errors in context expressions (do NOT use || fallbacks - blocked by Claude Code 2.1.7+):
- Git status: !`git status --porcelain=v2 --branch`
- Current branch: !`git branch --show-current`
- Remote URL: !`git remote -v`
Combining with GH CLI
For GitHub-specific operations, combine with gh commands:
gh repo view --json nameWithOwner --jq '.nameWithOwner'
git push origin main:$(gh pr view --json headRefName --jq '.headRefName')
Best Practices
- Use porcelain v2 for status when parsing programmatically
- Use --numstat for diff when counting changes
- Use custom --format for log when extracting specific fields
- Always add 2>/dev/null fallback in context expressions
- Prefer git switch/restore over checkout for clarity