Push
Prerequisites
gh CLI is installed and available in PATH.
gh auth status succeeds for GitHub operations in this repo.
Goals
- Push current branch changes to
origin safely.
- Create a PR if none exists for the branch, otherwise update the existing PR.
- Keep branch history clean when remote has moved.
Related Skills
pull: use this when push is rejected or sync is not clean (non-fast-forward,
merge conflict risk, or stale branch).
Steps
- Identify current branch and confirm remote state.
- Run local validation before pushing:
go build ./...
go test ./... -count=1
go vet ./...
test -z "$(gofmt -l .)"
- Push branch to
origin with upstream tracking if needed, using whatever
remote URL is already configured.
- If push is not clean/rejected:
- If the failure is a non-fast-forward or sync problem, run the
pull
skill to merge origin/main, resolve conflicts, and rerun validation.
- Push again; use
--force-with-lease only when history was rewritten.
- If the failure is due to auth, permissions, or workflow restrictions on
the configured remote, stop and surface the exact error instead of
rewriting remotes or switching protocols as a workaround.
- Ensure a PR exists for the branch:
- If no PR exists, create one.
- If a PR exists and is open, update it.
- If branch is tied to a closed/merged PR, create a new branch + PR.
- Write a proper PR title that clearly describes the change outcome.
- For branch updates, explicitly reconsider whether current PR title still
matches the latest scope; update it if it no longer does.
- Write/update PR body:
- If
.github/pull_request_template.md exists, use it as a guide.
- Fill every section with concrete content for this change.
- If PR already exists, refresh body content so it reflects the total PR
scope, not just the newest commits.
- Reply with the PR URL from
gh pr view.
Commands
# Identify branch
branch=$(git branch --show-current)
# Validation gate
go build ./...
go test ./... -count=1
go vet ./...
test -z "$(gofmt -l .)"
# Initial push: respect the current origin remote.
git push -u origin HEAD
# If that failed because the remote moved, use the pull skill. After
# pull-skill resolution and re-validation, retry the normal push:
git push -u origin HEAD
# If the configured remote rejects the push for auth, permissions, or workflow
# restrictions, stop and surface the exact error.
# Only if history was rewritten locally:
git push --force-with-lease origin HEAD
# Ensure a PR exists (create only if missing)
pr_state=$(gh pr view --json state -q .state 2>/dev/null || true)
if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then
echo "Current branch is tied to a closed PR; create a new branch + PR." >&2
exit 1
fi
# Write a clear, human-friendly title that summarizes the shipped change.
pr_title="<clear PR title written for this change>"
if [ -z "$pr_state" ]; then
gh pr create --title "$pr_title"
else
# Reconsider title on every branch update; edit if scope shifted.
gh pr edit --title "$pr_title"
fi
# Show PR URL for the reply
gh pr view --json url -q .url
Notes
- Do not use
--force; only use --force-with-lease as the last resort.
- Distinguish sync problems from remote auth/permission problems:
- Use the
pull skill for non-fast-forward or stale-branch issues.
- Surface auth, permissions, or workflow restrictions directly instead of
changing remotes or protocols.
1---2name: push3description: Push current branch changes to origin and create or update the corresponding pull request; use when asked to push, publish updates, or create pull request.4---56# Push78## Prerequisites910- `gh` CLI is installed and available in `PATH`.11- `gh auth status` succeeds for GitHub operations in this repo.1213## Goals1415- Push current branch changes to `origin` safely.16- Create a PR if none exists for the branch, otherwise update the existing PR.17- Keep branch history clean when remote has moved.1819## Related Skills2021- `pull`: use this when push is rejected or sync is not clean (non-fast-forward,22 merge conflict risk, or stale branch).2324## Steps25261. Identify current branch and confirm remote state.272. Run local validation before pushing:28 ```bash29 go build ./...30 go test ./... -count=131 go vet ./...32 test -z "$(gofmt -l .)"33 ```343. Push branch to `origin` with upstream tracking if needed, using whatever35 remote URL is already configured.364. If push is not clean/rejected:37 - If the failure is a non-fast-forward or sync problem, run the `pull`38 skill to merge `origin/main`, resolve conflicts, and rerun validation.39 - Push again; use `--force-with-lease` only when history was rewritten.40 - If the failure is due to auth, permissions, or workflow restrictions on41 the configured remote, stop and surface the exact error instead of42 rewriting remotes or switching protocols as a workaround.435. Ensure a PR exists for the branch:44 - If no PR exists, create one.45 - If a PR exists and is open, update it.46 - If branch is tied to a closed/merged PR, create a new branch + PR.47 - Write a proper PR title that clearly describes the change outcome.48 - For branch updates, explicitly reconsider whether current PR title still49 matches the latest scope; update it if it no longer does.506. Write/update PR body:51 - If `.github/pull_request_template.md` exists, use it as a guide.52 - Fill every section with concrete content for this change.53 - If PR already exists, refresh body content so it reflects the total PR54 scope, not just the newest commits.557. Reply with the PR URL from `gh pr view`.5657## Commands5859```sh60# Identify branch61branch=$(git branch --show-current)6263# Validation gate64go build ./...65go test ./... -count=166go vet ./...67test -z "$(gofmt -l .)"6869# Initial push: respect the current origin remote.70git push -u origin HEAD7172# If that failed because the remote moved, use the pull skill. After73# pull-skill resolution and re-validation, retry the normal push:74git push -u origin HEAD7576# If the configured remote rejects the push for auth, permissions, or workflow77# restrictions, stop and surface the exact error.7879# Only if history was rewritten locally:80git push --force-with-lease origin HEAD8182# Ensure a PR exists (create only if missing)83pr_state=$(gh pr view --json state -q .state 2>/dev/null || true)84if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then85 echo "Current branch is tied to a closed PR; create a new branch + PR." >&286 exit 187fi8889# Write a clear, human-friendly title that summarizes the shipped change.90pr_title="<clear PR title written for this change>"91if [ -z "$pr_state" ]; then92 gh pr create --title "$pr_title"93else94 # Reconsider title on every branch update; edit if scope shifted.95 gh pr edit --title "$pr_title"96fi9798# Show PR URL for the reply99gh pr view --json url -q .url100```101102## Notes103104- Do not use `--force`; only use `--force-with-lease` as the last resort.105- Distinguish sync problems from remote auth/permission problems:106 - Use the `pull` skill for non-fast-forward or stale-branch issues.107 - Surface auth, permissions, or workflow restrictions directly instead of108 changing remotes or protocols.