git-and-github
Scannednpx machina-cli add skill lklimek/claudius/git-and-github --openclawGitHub Workflow
Use git for repository operations (clone, fetch, commit, push, branch, merge). Use gh for GitHub-specific operations that have no git equivalent (PRs, issues, releases, Actions, checks). Full gh reference: https://cli.github.com/manual/
Attribution: Every PR, issue, and comment posted to GitHub must include this footer (blank line before it):
<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Committing
Stage specific files — never git add . or git add -A.
git add <file1> <file2>
git commit -m "$(cat <<'EOF'
<type>: <description>
<optional body>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
EOF
)"
Use conventional commits (feat, fix, docs, refactor, test, chore, perf). Append ! for breaking changes.
Pushing
Always ask the user for explicit confirmation before every push. Never push automatically — even after committing or creating a PR. Even if the user agreed to push earlier, ask again before next push.
Never force-push. Never amend commits. Always create new commits. If force-push is required, ask the user to do it manually.
Pull Requests
Creating a PR
Check for a PR template first:
git ls-tree HEAD --name-only -r .github/ | grep -i pull_request_template
If a template exists, read and fill it in. When applicable, include an informal user story (what the user can achieve, no technical details — start with "Imagine you are...").
Always create PRs as drafts:
gh pr create --draft --title "<type>: <description>" --body "$(cat <<'EOF'
## Issue being fixed or feature implemented
### User Story
### Details
Closes #<issue-number>
## What was done?
<description of changes>
## How has this been tested?
<testing details>
## Breaking Changes
None
## Checklist
- [x] I have performed a self-review of my own code
- [x] I have added or updated relevant tests
- [x] I have made corresponding changes to the documentation if needed
<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
EOF
)"
Reviewing a PR
Never submit a final review (approve/request-changes). Always create draft reviews. The user must publish the review themselves.
Always use wrapper scripts (via ../../scripts/) — they handle pagination, filtering, and input validation.
Create draft reviews by omitting the "event" field. gh-post-review.sh enforces this by stripping any event field:
cat > "$SESSION_DIR/pr-review.json" << 'ENDJSON'
{
"commit_id": "<SHA>",
"body": "Review summary.\n\n<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>",
"comments": [
{"path": "src/file.rs", "line": 42, "side": "RIGHT", "body": "Finding here."}
]
}
ENDJSON
../../scripts/gh-post-review.sh <owner> <repo> <number> "$SESSION_DIR/pr-review.json"
Available scripts (../../scripts/):
gh-fetch-review-comments.sh <owner> <repo> <pr>
→ {id, path, line, original_line, body, user, in_reply_to_id, html_url}
gh-fetch-reviews.sh <owner> <repo> <pr>
→ {id, state, submitted_at, body, user}
gh-post-review.sh <owner> <repo> <pr> <json_file>
→ Posts draft review. Input: {commit_id, body, comments: [{path, line, side, body}]}
gh-request-reviewer.sh <owner> <repo> <pr> <reviewer>
gh-list-review-threads.sh <owner> <repo> <pr>
→ {id, isResolved, comments: [{databaseId, path, body}]}
gh-resolve-review-thread.sh <thread_id>
→ Ask user before resolving. Never resolve partially addressed threads.
gh-pr-base-sha.sh <owner> <repo> <pr>
→ Base commit SHA.
diff-anchors.py <file_path> [...]
→ "path → sha256". For diff URLs: ...files#diff-<SHA256>R<line>
ghsudo [--org ORG] <cmd> | --setup <org> | --verify [org] | --revoke [org] | --list
→ Per-org elevated token management (pip install ghsudo). See "Elevated Permissions" section below.
For PR-level (non-diff) comments: gh pr view <number> --json comments --jq '.comments[] | {author: .author.login, body, url}'
Issues
Check for issue templates (git ls-tree HEAD --name-only -r .github/ | grep -i issue_template) before creating. Always append attribution footer.
Feature/enhancement issues must include a ### User Story section — an informal story describing what the user can achieve (no technical details). Start with "As a <persona>, I want to ... so that ...". Multiple personas are fine. Place user stories before technical details.
Safety Rules
- Always ask before pushing or publishing to GitHub — pushes, PRs, issues, comments, reviews. Commits are local and don't require confirmation, but pushes always do.
- Never force-push. Never amend commits. Always create new commits. If force-push is needed, ask the user to do it manually.
- Never use
git add .orgit add -A— stage specific files - Never use interactive flags (
-i) — requires terminal input - Never skip hooks (
--no-verify) unless explicitly requested - Check for
.env, credentials, or secret files before staging — warn if found - Check for PR/issue templates before creating — use them if they exist
- Avoid
gh api— prefer high-levelghsubcommands. Usegh apionly for read-only queries when no subcommand exists. Never usegh apifor write operations — use wrapper scripts orghsubcommands instead.
Escaping and Formatting
- Use HEREDOCs (
<<'EOF') for multi-line bodies - When using
gh api(read-only only), prefer--jqover| jq—--jqis processed internally bygh, avoiding shell expansion issues (!triggers history expansion)
Elevated Permissions (ghsudo)
When a gh or git command fails with HTTP 403 (Forbidden), 404 (Not Found), or "Resource not accessible", re-run it through ghsudo to request elevated write permissions. GitHub may return 404 instead of 403 for private resources when the token lacks sufficient permissions.
ghsudo <original-command-and-args>
# Or with explicit org:
ghsudo --org dashpay <original-command-and-args>
ghsudo auto-detects the target org from -R owner/repo flags or the current repo's git remote. It shows a GUI popup (or terminal prompt) with the exact command and org, asking the user to approve. If approved, it re-executes the command with the org's stored read-write token.
- Exit code 4 → no token stored. Tell the user to run
ghsudo --setup <org>to configure their read-write PAT. - Exit code 2 → user denied the request. Do not retry.
- Exit code 3 → no GUI and no terminal available. Inform the user.
Troubleshooting
ghcommand fails with "Projects (classic)" GraphQL error →ghversion is outdated, upgrade needed.
Source
git clone https://github.com/lklimek/claudius/blob/main/skills/git-and-github/SKILL.mdView on GitHub Overview
Guides when to use git for repository actions and when to use gh for GitHub-specific tasks, such as PRs, issues, releases, and Actions. It also enforces safe practices like explicit pushes, conventional commits, and a mandatory attribution footer for PRs and comments. Following these guidelines helps maintain a clean history and clear collaboration.
How This Skill Works
Git handles local and remote repository actions (clone, fetch, commit, push, branch, merge) while gh covers GitHub-specific flows that have no git substitute. The skill also prescribes an attribution footer in all PRs and comments, requires drafting PRs, and uses wrapper scripts to standardize reviews.
When to Use It
- Stage exact files with git add <file1> <file2> instead of git add . or git add -A.
- Commit using conventional types (feat, fix, docs, refactor, test, chore, perf) and append ! for breaking changes.
- Always confirm before pushing; never push automatically.
- When GitHub is involved, use gh for PRs, issues, releases, and Actions that have no git equivalent.
- Check for a PR template, draft a user story, and include the Co-authored attribution footer in PRs and comments.
Quick Start
- Step 1: Stage the files you changed with git add <file1> <file2>.
- Step 2: Commit with a conventional message and include the Co-Authored-By footer in the body.
- Step 3: Create a draft PR with gh pr create --draft --title '<type>: <description>' and use the PR template for the body.
Best Practices
- Stage files selectively with git add <files> to avoid unintended changes.
- Follow conventional commits and use ! for breaking changes.
- Always seek explicit confirmation before pushing; no auto-push.
- Never force-push or amend commits; create new commits instead.
- Check for a PR template and draft a user story when creating PRs; include attribution footer.
Example Use Cases
- Committing with a type and description in the form <type>: <description> plus a Co-Authored-By footer.
- Creating a draft PR with gh pr create --draft --title '<type>: <description>' and a body.
- Using wrapper scripts (e.g., gh-post-review.sh) to post draft reviews.
- Reading and filling PR templates from .github/pull_request_template before opening a PR.
- Posting PRs/comments that include the attribution footer.