Problem
When using /commit-push-pr on a branch that already has a draft PR, the command fails with:
git push -u origin <branch> failed: error: failed to push some refs to 'github.com:...'
This happens because the remote branch may have diverged since the last push (e.g., rebased via GitHub UI, updated from another machine, or modified by CI).
Current Behavior
The command does a simple git push which fails if the remote branch is ahead or has diverged.
Expected Behavior
The command should:
- Detect if the remote branch exists and has diverged
- Either pull/rebase automatically, or prompt the user for how to proceed
- Skip
gh pr create if a PR already exists for the branch
Workaround
When this happens, users can manually run:
git pull --rebase origin <branch-name>
git push
Or to overwrite the remote:
git push --force-with-lease
Suggested Fix
Before pushing, check if the remote branch exists and compare commits:
git fetch origin
if git rev-parse --verify origin/<branch> >/dev/null 2>&1; then
# Remote exists, check if we need to rebase
if ! git merge-base --is-ancestor origin/<branch> HEAD; then
git pull --rebase origin <branch>
fi
fi
git push -u origin <branch>
Also check for existing PR before creating:
if ! gh pr view --json number >/dev/null 2>&1; then
gh pr create ...
fi
Problem
When using
/commit-push-pron a branch that already has a draft PR, the command fails with:This happens because the remote branch may have diverged since the last push (e.g., rebased via GitHub UI, updated from another machine, or modified by CI).
Current Behavior
The command does a simple
git pushwhich fails if the remote branch is ahead or has diverged.Expected Behavior
The command should:
gh pr createif a PR already exists for the branchWorkaround
When this happens, users can manually run:
Or to overwrite the remote:
Suggested Fix
Before pushing, check if the remote branch exists and compare commits:
Also check for existing PR before creating: