AgentSkillsCN

git-commit-push

按照常规分支前缀与安全检查,对更改进行暂存、提交并推送。当用户请求提交、推送、保存或发布本地更改至GitHub,或希望在此项目中采用标准的提交工作流程时使用此功能。

SKILL.md
--- frontmatter
name: git-commit-push
description: 'Stage, commit, and push changes with conventional branch prefixes and safety checks. Use when the user asks to commit, push, save, or publish local changes to GitHub, or wants a standard commit workflow in this project.'

Git Commit + Push

Follow this workflow to commit and push changes safely with the project's branch rules.

Workflow

  1. Confirm repository root and show status.
  2. Ensure the working tree is clean after staging.
  3. Enforce branch policy:
  • If current branch is main, create or request a feature/*, chore/*, fix/*, docs/*, refactor/*, or test/* branch before committing.
  • Before creating a new branch from main, sync main first with git fetch origin main then git pull --ff-only origin main.
  • Prefer chore/<short-desc> for environment/tooling changes.
  1. Stage changes with git add -A.
  2. If behavior/logic changed, confirm tests were added or updated in the same diff.
  3. Create a commit with a clear message.
  4. Push with upstream tracking: git push -u origin <branch>.

Preferred Commands

  • Status: git status -sb
  • Branch: git branch --show-current
  • Sync main then create branch: git fetch origin main && git pull --ff-only origin main && git checkout -b chore/<short-desc>
  • Stage: git add -A
  • Commit: git commit -m "<message>"
  • Push: git push -u origin <branch>

Bundled Script

Use scripts/commit_push.sh for a consistent flow:

code
./scripts/commit_push.sh ["<message>"] [chore/<short-desc>]

Behavior:

  • If on main, requires a branch name as the second argument.
  • If on main, it syncs local main to latest origin/main before creating the new branch.
  • Enforces feature/*, chore/*, fix/*, docs/*, refactor/*, or test/* naming.
  • Stages, commits, and pushes.
  • If message is omitted, generates one from staged file names.

Notes

  • If there are no changes to commit, stop and report.
  • If behavior changed without corresponding test updates, pause and add tests first.
  • If push fails, surface the error and suggest git pull --rebase only when needed.