name: git-commit-push description: Create a clean git commit and push it to the correct remote branch with safety checks. Use when asked to commit changes, write a commit message, push a branch, or finalize local repository updates.
Git Commit Push
Execute a reliable workflow for committing and pushing code changes without rewriting history or including unrelated edits.
Workflow
- Inspect repository state before modifying history.
- Stage only intended files.
- Commit with a clear, scoped message.
- Push to the correct remote/branch and verify success.
Step 1: Inspect State
Run:
git status --shortgit branch --show-currentgit remote -v
Guardrails:
- If no changes exist, stop and report nothing to commit.
- If unrelated local changes exist, stage specific files instead of using broad staging.
- If branch is detached, stop and ask for branch target.
Step 2: Stage Intended Files
Preferred:
git add <file1> <file2> ...
Only use git add -A when the user clearly wants all tracked and untracked changes included.
Re-check staged set:
git status --shortgit diff --cached --statgit diff --cached
If staged content does not match intent, unstage and retry:
git restore --staged <file>(or targeted restaging)
Step 3: Commit
Message style:
- Use imperative, concise subject (about 50-72 chars).
- Scope by area when helpful (example:
api: validate token expiry). - Include a body only when context or tradeoffs matter.
Run:
git commit -m "<subject>"- Or:
git commit -m "<subject>" -m "<body>"
If commit fails due to no staged changes, return to staging.
Step 4: Push Safely
Check upstream:
git rev-parse --abbrev-ref --symbolic-full-name @{u}
If missing upstream:
git push -u origin <current-branch>
Otherwise:
git push
For non-default remote targets:
git push <remote> <branch>
After push:
- Confirm branch and remote in output.
- Report commit hash with
git rev-parse --short HEAD.
Safety Rules
- Do not use destructive history rewrite commands unless explicitly requested.
- Do not push force updates unless explicitly requested.
- Do not commit generated secrets, credentials, or local-only config files.
- Do not include unrelated modified files in the same commit.
- Summarize exactly what was committed and where it was pushed.
Output Template
Report:
- Branch name
- Remote target
- Commit hash and message subject
- Files included in the commit
- Push result (success/failure and reason)
References
references/playbook.md