Pushing to a pull request that isn't yours - Frank DENIS random thoughts.
Skip to main content
I’ve been using Git and GitHub for 18 years.
But I had to push to someone else’s pull request today, and I couldn’t do it without asking an LLM, and it even didn’t do what I wanted. Yay, that’s embarrassing.
To modify files already changed by the PR, this is trivial and can be done directly through the GitHub UI. But if additional files need to be modified, some local Git command magic is required.
So this is the reference I wish I’d had open in a tab.
Find the source branch
gh pr view 42 --repo user/project \<br>--json headRepository,headRefName,isCrossRepository
You need two things from that output: the repository that owns the PR branch, and the branch name.
If the PR came from the same repository, the branch lives on origin.
If the PR came from a fork, the branch lives on the fork. origin is still the upstream repository. Pushing to origin some-local-name:their-branch will create or update a branch in the upstream repository, not in the contributor’s fork.
Fetch the PR
pull//head: as the remote branch name is the key.
git fetch origin pull/42/head:pr-42<br>git switch pr-42
Now make your edits and commit them normally.
Push to the source branch
For a PR branch in the same repository:
git push origin HEAD:their-branch
For a PR branch in a fork:
git push git@github.com:contributor/project.git HEAD:their-branch
You can add the fork as a remote if you prefer:
git remote add contributor git@github.com:contributor/project.git<br>git push contributor HEAD:their-branch
The important part is the destination repository. The left side is your local branch or commit. The right side is the branch that GitHub is using as the pull request’s head.
Refuse to force push
After a while, you may want to squash commits and force push. Be careful.
git fetch git@github.com:contributor/project.git their-branch<br>git merge-base --is-ancestor FETCH_HEAD HEAD \<br>&& echo "fast-forward ok"
If it isn’t a fast-forward, stop. A force push would silently delete the author’s commits. Talk to them first.
Hope this helps.
Related Posts
May 17, 2026<br>Bun's problem may be developing in the open
Apr 26, 2026<br>aHash is not a PRF
Apr 13, 2026<br>Swival is the AI agent I actually wanted
Apr 11, 2026<br>Configuration flags are where software goes to rot
Feb 17, 2026<br>Fast sorting, branchless by design