how can I push a commit to a branch of a pr that I pulled locally with "git fetch origin…
- User
how can I push a commit to a branch of a pr that I pulled locally with "git fetch origin pull/41/head:pr-41"?
- Assistant
Ah, I see exactly what you’re trying to do. You’ve fetched a PR locally like this: bashCopy codegit fetch origin pull/41/head:pr-41
This creates a local branch pr-41 that tracks the remote PR, but it does not set up any push target. PRs on GitHub are typically on someone else’s fork, so you can’t push directly to the original PR unless you have write access to that fork. Here’s how you can handle it:
Option 1: If you have write access to the PR branch
Check out the branch:
bashCopy codegit checkout pr-41
Make your commit:
bashCopy codegit add . git commit -m "Your changes"
Push back to the same branch:
bashCopy codegit push origin pr-41:refs/pull/41/head
This explicitly tells Git to push your local pr-41 branch to the PR branch.
Option 2: If you don’t have write access
Create a new branch on your fork:
bashCopy codegit checkout -b my-fix-pr-41
Push it to your fork:
- User
git push origin pr-41:refs/pull/41/head
Enumerating objects: 15, done. Counting objects: 100% (15/15), done. Delta compression using up to 8 threads Compressing objects: 100% (11/11), done. Writing objects: 100% (11/11), 1.78 KiB | 1.78 MiB/s, done. Total 11 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0) remote: Resolving deltas: 100% (7/7), completed with 3 local objects. To https://github.com/shachardon/share-lm.git ! [remote rejected] pr-41 -> refs/pull/41/head (deny updating a hidden ref) error: failed to push some refs to 'https://github.com/shachardon/share-lm.git'
- Assistant
Ah — that error is expected. GitHub does not allow pushing directly to refs/pull/*/head. That’s considered a “hidden ref” and is read-only for PRs you don’t own. So git push origin pr-41:refs/pull/41/head will always fail unless you have write access to the branch that the PR originates from. Here’s what you should do instead:
- Push to a branch on your fork
Create a new branch from your local pr-41:
bashCopy codegit checkout -b fix-pr-41
Push it to your fork (assuming your fork is origin):
bashCopy codegit push origin fix-pr-41
- Open a new PR
Go to GitHub and create a new PR from fix-pr-41 to the original PR branch.
This will allow the maintainers of the original repo to review and merge your changes.
⚡ Summary: You cannot push directly to a PR branch unless you have write access to the branch it comes from. The usual workflow is to push to your own branch/fork and open a PR against the original branch. If you want, I can give a one-liner workflow for editing any PR locally and submitting your changes correctly. Do you want me to do that?
- User
I know what the original fork name is, could I use that?
- Assistant
Yes — exactly! If you know the original fork’s repository URL (the one that created the PR) and you have write access to it, you can push directly to its branch. Here’s how to do it safely:
- Add the original fork as a remote bashCopy codegit remote add upstream https://github.com/username/repo.git
Replace username/repo.git with the fork URL.
You can verify it with:
bashCopy codegit remote -v
- Push your local branch to the fork bashCopy codegit checkout pr-41 git push upstream pr-41
This pushes your pr-41 changes to the fork’s branch.
The original PR will automatically update with your new commit.
✅ Notes
If the fork uses a different branch name, use that instead:
bashCopy codegit push upstream pr-41:branch-name
If you don’t have write access to the fork, GitHub will reject it. In that case, you’ll still need to push to your own fork and open a new PR.
If you want, I can write a minimal step-by-step workflow to update any PR locally using the original fork directly. It’s very handy. Do you want me to do that?
- User
where the specific branch is indicated?
- Assistant
Ah, I see — you want to know which branch of the original fork the PR is coming from, because that’s what you’d push to. GitHub PRs are basically “merge requests” from a source branch in someone’s fork into the target branch of the main repo. Here’s how to find it:
Option 1: On GitHub
Open the PR in your browser.
At the top of the PR, GitHub shows something like:
makefileCopy codeusername:feature-branch → main-repo:main
username → the fork owner
feature-branch → the branch in their fork
main-repo:main → where the PR is being merged
That feature-branch is the branch you would push to.
Option 2: From the CLI
You can fetch the PR info:
bashCopy codegit fetch origin pull/41/head:pr-41
Then see the PR details on GitHub (because GitHub hides the original branch in the fetch). Alternatively, you can use GitHub’s API:
bashCopy codecurl -s | jq '.head'