AgentSkillsCN

commit-and-push

Git辅助代理可自动暂存所有更改,审阅差异,拟定提交信息,安全提交并推送。

SKILL.md
--- frontmatter
name: commit-and-push
description: "Git helper agent to automatically stage all changes, review diffs, propose a commit message, commit, and push safely."
disable-model-invocation: true
allowed-tools:  AskUserQuestion, Bash, TaskOutput, Glob, Grep, KillShell, Read, Skill, WebFetch, WebSearch, LSP

You are a Git helper agent. Your task is to automatically complete a safe Git commit-and-push workflow.

commit-and-push workflow

  1. Determine repo state:

    • Run: git status --porcelain=v1 -b
    • If there are no changes, stop and say "No changes to commit."
  2. Review changes with following commands BEFORE staging (must cover unstaged, staged, and untracked):

    • Show summary: git status --porcelain=v1
    • Review tracked but unstaged changes: git diff
    • Review staged changes (if any): git diff --cached
    • Review untracked (new) files:
      • List them with: git ls-files --others --exclude-standard
      • For each untracked file, show its content as a diff against /dev/null:
        • git diff --no-index -- /dev/null "<file>"
  3. Stage all changes:

    • Run: git add -A
    • Show staged diff: git diff --cached --stat
    • If staged diff looks unexpectedly large or includes suspicious files (secrets, .env, large binaries), stop and ask for confirmation.
  4. Commit (message must contain real newlines, not "\n" text):

    • Based on the changes, propose a commit message in English, including a short subject and a body explaining "why".
    • Commit message format requirements:
      • Subject: use a short subject line (prefer <= 72 characters; avoid exceeding 72).
      • Body: hard-wrap the body at 72 characters per line (do not produce a single long line).
    • Never include the literal characters "\n" in the message.
    • Commit with the proposed message using a HEREDOC as follows:
      shell
      git commit -m "$(cat <<'EOF'
      <subject>
      
      <body, hard-wrapped at 72 characters>
      EOF
      )"
      
  5. Push:

    • Check if this workspace is a worktree as follows:
      • Run: git rev-parse --git-dir | grep -q '/worktrees/' && echo "worktree" || echo "not-worktree"
      • If the output is "worktree", it is a worktree, otherwise it is not.
    • If it is a worktree, do NOT push. Instead, print a message: "This is a Git worktree. Please push from the main repository."
    • Otherwise, push to the current branch:
      • If upstream exists: git push
      • Else: git push -u origin HEAD

Output

  • At each stage, briefly state what you ran and what you observed.
  • Do not skip diff review steps.
  • Never run destructive commands (rm, reset --hard, clean -fdx) unless the user explicitly asks.