/gh-push — Commit & Push
Push the current branch to the remote, optionally committing staged/unstaged changes first. Arguments passed: $ARGUMENTS.
Parse arguments
force/-f→ force-push (REQUIRES extra confirmation, see Safety below)no-commit→ skip the commit step, push existing commits onlymessage:"..."→ use this commit message instead of drafting one- Any other text → treat as commit message body
Steps
- Inspect state (run in parallel):
git status(no-uall)git diff(unstaged)git diff --stagedgit branch --show-currentgit log --oneline -5
- Decide what to commit:
- If there are no pending changes and no unpushed commits → nothing to do, tell the user.
- If there are pending changes and
no-commitwas NOT set → draft a commit. - If the user listed specific files in arguments, only stage those. Otherwise stage only files relevant to the described change — never
git add -Ablindly, to avoid pulling in secrets or unrelated work. - Show the user the file list and draft message, then confirm unless arguments already specified a message.
- Commit (if applicable) using HEREDOC:
```
git commit -m "$(cat <<'EOF'
<subject>
<body if needed>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
EOF
)"
```
Match the repo's commit-message style (check recent git log).
- Push:
- Default:
git push(orgit push -u origin <branch>if upstream not set) - Force-push: only if
forcewas passed AND the branch is notmain/masterAND the user re-confirms in this turn. - NEVER
--no-verify.
- After push:
- Show
git statusto confirm clean. - If a PR exists for the branch (
gh pr view --json url,state), print its URL. - If no PR and the branch isn't main, suggest creating one (but don't do it unprompted).
Safety
- Pushing to
main/masterdirectly: warn and confirm once before pushing. - Force-push to
main/master: refuse unless the user explicitly says "force push main, I mean it." - If the pre-push hook fails, do NOT retry with
--no-verify. Investigate, report, stop. - If
git statusshows an uncommitted.env/credentials*/*.pemin the staging candidates, flag it and ask before staging.