AgentSkillsCN

commit-push

在当前分支上提交更改并推送到远程仓库。当你希望在一个工作流中同时提交本地更改并将其推送到上游,同时利用分支保护机制防止直接修改主分支或默认分支时,可选用此方法。

SKILL.md
--- frontmatter
name: commit-push
description: Commit changes and push to the current branch remote. Use when you want to commit local changes and push them upstream in one workflow, with branch protection against main/master.

Commit and Push

Commit changes on the current branch and push to the remote.

Steps

  1. Check branch (prevent direct pushes to main/master)

    bash
    BRANCH=$(git branch --show-current)
    if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
      echo "Direct pushes to main/master are not allowed"
      exit 1
    fi
    
  2. Stage changes

    bash
    git add -A
    
  3. Commit

    bash
    git commit -m "<prefix>: <summary (imperative, concise)>"
    
  4. Push

    bash
    git push -u origin "$BRANCH"
    

One-liner

bash
MSG="fix: remove unnecessary debug log output" \
BRANCH=$(git branch --show-current) && \
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then \
  echo "Direct pushes to main/master not allowed"; exit 1; \
fi && \
git add -A && git commit -m "$MSG" && git push -u origin "$BRANCH"

Notes

  • Always review diffs with git status or git diff before executing
  • Use conventional commit prefixes: feat, fix, refactor, perf, test, docs, build, ci, chore, style, revert