Git & GitHub Workflow
Use gh CLI (GitHub) for all remote operations. Commit and push directly without confirmation. Only PR requires explicit user approval.
⚠️ CRITICAL CONSTRAINT
NEVER automatically commit and push after making edits.
This skill should ONLY activate when:
- User explicitly asks: "commit", "push", "create PR", "提交", "推送"
- User invokes:
/git-gh command
- User explicitly requests git operations
DO NOT:
- Auto-commit after editing files
- Suggest committing after each change
- Be proactive about git operations
WAIT for the user to initiate.
Interactive Mode
When this skill is invoked, immediately run git status --short in the background, then ask the user to choose via AskUserQuestion:
Options:
| # |
Option |
Action |
| 默认/回车 |
Commit & Push |
Execute full commit + push flow (Section 1 + 2) |
| 1 |
Staged Files |
Show git diff --cached --stat + git diff --cached, then ask next action |
| 2 |
Unstaged Files |
Show git status --short + git diff --stat, then ask next action |
| Flow after viewing files (option 1 or 2): |
|
|
- Ask user: proceed to commit & push / stage or unstage specific files / go back
- After staging/unstaging, loop back to the choice menu
1. Commit
Before Committing
Run in parallel to gather context:
git status — untracked and modified files
git diff — staged and unstaged changes
git log --oneline -10 — recent commit style
Commit Message Rules
- Write in Chinese or English depending on the project's existing commit style
- Format:
type: short summary — one line, concise, human-readable
- Types:
feat, fix, refactor, docs, chore, test, style, perf
- Focus on what changed and why, not how
- No emojis unless user requests
Good Examples
feat: add user login with email verification
fix: resolve race condition in batch processing
refactor: extract validation logic into shared module
docs: update API endpoint descriptions
chore: upgrade dependencies to latest stable
Bad Examples
update files # too vague
feat: add feature # which feature?
wip # meaningless
fix bug # what bug?
Steps
- Gather context (status, diff, recent log) — run in parallel
- Stage specific files by name (
git add <file>), avoid git add -A
- Draft commit message based on actual changes
- Create commit directly
- Run
git status to verify
Never commit files that likely contain secrets (.env, credentials).
2. Push
Steps
- Check if branch tracks a remote:
git branch -vv
- If no upstream, push with:
git push -u origin <branch>
- If upstream exists:
git push
- Never force push unless user explicitly requests
Current Branch Check
After commit, check if current branch is not main/master. If on a feature branch and commit + push succeeded, proceed to step 3.
3. Pull Request
When to Ask
After a successful commit + push on a non-main branch, ask the user:
Commit and push completed. Would you like to create a pull request?
Never create a PR automatically. Always wait for explicit user confirmation.
When NOT to Ask
- Already on
main or master
- User only asked to commit (not push)
- PR already exists for this branch
PR Creation Steps
- Run in parallel to gather full context:
git status
git diff
git log main..HEAD --oneline — all commits on this branch
git diff main...HEAD — full diff from base
- Analyze all changes, draft title and body
- PR title: under 70 chars, concise summary of the change
- PR body format:
## Summary
- Bullet points of key changes (1-3 items)
## Test plan
- Checklist of verification steps
🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Present to user for approval — include suggested labels, assignees, reviewers
- Push with
-u if needed, then create via gh pr create
- Return the PR URL
PR Metadata
When creating a PR, suggest and apply labels, assignees, and reviewers:
| Parameter |
Flag |
Example |
| Labels |
--label |
--label "enhancement,backend" |
| Assignees |
--assignee |
--assignee "user1,user2" |
| Reviewers |
--reviewer |
--reviewer "user1" |
| Milestone |
--milestone |
--milestone "v2.0" |
| Project |
--project |
--project "Roadmap" |
| How to suggest metadata: |
|
|
- Labels: infer from change type (
feat → enhancement, fix → bug, docs → documentation)
- Assignees: default to the current user (
@me) unless the user specifies others
- Reviewers: ask the user who should review
When presenting the PR for approval, include the metadata:
Title: feat: add user login
Labels: enhancement
Assignees: @me
Reviewers: (ask user)
To update an existing PR's metadata:
gh pr edit <number> --add-label "enhancement" --add-assignee "username"
gh pr create Template
gh pr create --title "the title" \
--label "enhancement" \
--assignee "@me" \
--body "$(cat <<'EOF'
## Summary
<bullets>
## Test plan
<checklist>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"
Quick Reference
| Action |
Command |
| Check status |
git status |
| Stage files |
git add <file> |
| Commit |
git commit -m "msg" |
| Push (new branch) |
git push -u origin <branch> |
| Push (existing) |
git push |
| Create PR |
gh pr create --title "..." --body "..." --label "..." --assignee "..." |
| Edit PR metadata |
gh pr edit <n> --add-label "..." --add-assignee "..." |
| Check existing PRs |
gh pr list |
| View PR |
gh pr view <number> |
Safety Rules
- Never force push to main/master
- Never auto-create PRs
- Never commit secret files (.env, credentials)
- Never use
git add -A — stage specific files
- Never skip pre-commit hooks (
--no-verify)
1---2name: amlei-git-gh3description: Guide for git commit, push, and PR using gh CLI (GitHub). Use when committing code, pushing to remote, creating pull requests, managing branches, or any git workflow. Covers commit message conventions, push strategies, and PR creation with confirmation gates.4---5# Git & GitHub Workflow6Use `gh` CLI (GitHub) for all remote operations. Commit and push directly without confirmation. Only PR requires explicit user approval.7## ⚠️ CRITICAL CONSTRAINT8**NEVER automatically commit and push after making edits.**9This skill should ONLY activate when:10- User explicitly asks: "commit", "push", "create PR", "提交", "推送"11- User invokes: `/git-gh` command12- User explicitly requests git operations13**DO NOT:**14- Auto-commit after editing files15- Suggest committing after each change16- Be proactive about git operations17**WAIT for the user to initiate.**18## Interactive Mode19When this skill is invoked, immediately run `git status --short` in the background, then ask the user to choose via `AskUserQuestion`:20**Options:**21| # | Option | Action |22|---|--------|--------|23| 默认/回车 | Commit & Push | Execute full commit + push flow (Section 1 + 2) |24| 1 | Staged Files | Show `git diff --cached --stat` + `git diff --cached`, then ask next action |25| 2 | Unstaged Files | Show `git status --short` + `git diff --stat`, then ask next action |26**Flow after viewing files (option 1 or 2):**27- Ask user: proceed to commit & push / stage or unstage specific files / go back28- After staging/unstaging, loop back to the choice menu29## 1. Commit30### Before Committing31Run in parallel to gather context:32- `git status` — untracked and modified files33- `git diff` — staged and unstaged changes34- `git log --oneline -10` — recent commit style35### Commit Message Rules36- Write in **Chinese or English** depending on the project's existing commit style37- Format: `type: short summary` — one line, concise, human-readable38- Types: `feat`, `fix`, `refactor`, `docs`, `chore`, `test`, `style`, `perf`39- Focus on **what changed and why**, not how40- No emojis unless user requests41### Good Examples42```43feat: add user login with email verification44fix: resolve race condition in batch processing45refactor: extract validation logic into shared module46docs: update API endpoint descriptions47chore: upgrade dependencies to latest stable48```49### Bad Examples50```51update files # too vague52feat: add feature # which feature?53wip # meaningless54fix bug # what bug?55```56### Steps571. Gather context (status, diff, recent log) — run in parallel582. Stage specific files by name (`git add <file>`), avoid `git add -A`593. Draft commit message based on actual changes604. Create commit directly615. Run `git status` to verify62Never commit files that likely contain secrets (.env, credentials).63## 2. Push64### Steps651. Check if branch tracks a remote: `git branch -vv`662. If no upstream, push with: `git push -u origin <branch>`673. If upstream exists: `git push`684. **Never force push** unless user explicitly requests69### Current Branch Check70After commit, check if current branch is not `main`/`master`. If on a feature branch and commit + push succeeded, proceed to step 3.71## 3. Pull Request72### When to Ask73After a successful commit + push on a **non-main branch**, ask the user:74> Commit and push completed. Would you like to create a pull request?75**Never create a PR automatically.** Always wait for explicit user confirmation.76### When NOT to Ask77- Already on `main` or `master`78- User only asked to commit (not push)79- PR already exists for this branch80### PR Creation Steps811. Run in parallel to gather full context:82 - `git status`83 - `git diff`84 - `git log main..HEAD --oneline` — all commits on this branch85 - `git diff main...HEAD` — full diff from base862. Analyze all changes, draft title and body873. PR title: under 70 chars, concise summary of the change884. PR body format:89```markdown90## Summary91- Bullet points of key changes (1-3 items)92## Test plan93- Checklist of verification steps94🤖 Generated with [Claude Code](https://claude.com/claude-code)95```965. Present to user for approval — include suggested labels, assignees, reviewers976. Push with `-u` if needed, then create via `gh pr create`987. Return the PR URL99### PR Metadata100When creating a PR, suggest and apply labels, assignees, and reviewers:101| Parameter | Flag | Example |102|-----------|------|---------|103| Labels | `--label` | `--label "enhancement,backend"` |104| Assignees | `--assignee` | `--assignee "user1,user2"` |105| Reviewers | `--reviewer` | `--reviewer "user1"` |106| Milestone | `--milestone` | `--milestone "v2.0"` |107| Project | `--project` | `--project "Roadmap"` |108**How to suggest metadata:**109- **Labels**: infer from change type (`feat` → `enhancement`, `fix` → `bug`, `docs` → `documentation`)110- **Assignees**: default to the current user (`@me`) unless the user specifies others111- **Reviewers**: ask the user who should review112**When presenting the PR for approval**, include the metadata:113```114Title: feat: add user login115Labels: enhancement116Assignees: @me117Reviewers: (ask user)118```119**To update an existing PR's metadata:**120```bash121gh pr edit <number> --add-label "enhancement" --add-assignee "username"122```123### gh pr create Template124```bash125gh pr create --title "the title" \126 --label "enhancement" \127 --assignee "@me" \128 --body "$(cat <<'EOF'129## Summary130<bullets>131## Test plan132<checklist>133🤖 Generated with [Claude Code](https://claude.com/claude-code)134EOF135)"136```137## Quick Reference138| Action | Command |139|---|---|140| Check status | `git status` |141| Stage files | `git add <file>` |142| Commit | `git commit -m "msg"` |143| Push (new branch) | `git push -u origin <branch>` |144| Push (existing) | `git push` |145| Create PR | `gh pr create --title "..." --body "..." --label "..." --assignee "..."` |146| Edit PR metadata | `gh pr edit <n> --add-label "..." --add-assignee "..."` |147| Check existing PRs | `gh pr list` |148| View PR | `gh pr view <number>` |149## Safety Rules150- Never force push to main/master151- Never auto-create PRs152- Never commit secret files (.env, credentials)153- Never use `git add -A` — stage specific files154- Never skip pre-commit hooks (`--no-verify`)