You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature or problem you’d like to solve
As a maintainer, I want to be able to push easily to the fork of a contributor (if he granted permission).
We need this to help unlock contributors if they are stuck on some difficult part.
Proposed solution
gh pr checkout 123
# do local commits to unlock the contributor
gh pr push
hub push does nothing else but execute git push, since hub is a proxy for git.
You will find that this works if the maintainer has given you access to their PR:
gh pr checkout 123
# (do some commits…)
git push
Reacted by Brent Shaffer, Lam Tang, Ian Storm Taylor, Janosh Riebesell, Jordan Harband, Frank Falor, Zachary Snow, Bryan Braun, Bernhard Kaindl, Max Howell and 9 more
Reacted by Jason R. Coombs, Alex Goodman, Evan Jones, Ben Hutton, Grzegorz Krukowski, edgar-db, Patrick Heneise, Michael Martinez, cospectrum, Lukas Klingsbo and 6 more
Last time I tried that, afaik it pushed to upstream repo, not forked repo. I want to contribute to the fork, as the contributor should be able to continue working on his PR updated with my fixes.
Will double-check to see if your suggestion works.
Reacted by Mislav Marohnić, Ophir LOJKINE, Vladimir Jimenez, Grzegorz Krukowski, edgar-db, Jason Axelson, Baptiste Mathus, pchiang-godaddy, Maks Rafalko, Sukka and 3 more
I run gh pr checkout 3613 and did my local commits.
Then I tried the git push but it didn't work. Only when I added remote repo URL did my commit end up showing in the PR
Only the 2nd command was able to push to the PR:
So it looks like git push may not be enough?
Not sure what is happening with the 403 error either. ochedru is a dev I worked with 2 years ago, on a totally different project 😅 he never contributed to Docusaurus in any way.
Recently upgraded GH cli and had to login again just before, not sure it's related...
Any idea what is happening here? and why ochedru show up in the error message?
I can try again on another PR soon if you need another case
@slorber Do you prefer HTTPS or SSH protocol for git cloning/pushing? It looks like you prefer SSH, but gh defaults to HTTPS, as evident by it setting up a HTTPS push URL after gh pr checkout.
You can change the default with:
gh config set git_protocol ssh -h github.com
From the Remote: permission to {REPO} denied to ochedru error message, I suspect that the git credential helper for HTTPS repos had some credentials cached that belong to ochedru. See:
$ git config credential.helper
osxkeychain
$ git credential-osxkeychain get <<<"host=github.comprotocol=https"
I'm having a very similar issue here with gh and HTTPS remotes.
$ gh pr checkout 123
From github.com:MyUser/myrepo
* [new ref] refs/pull/123/head -> branchname
Switched to branch 'branchname'
$ git push
Username for 'https://github.com': ^C
$ gh auth status
github.com
✓ Logged in to github.com as bsiegel (~/.config/gh/hosts.yml)
✓ Git operations for github.com configured to use https protocol.
I don't understand why gh thinks I am logged in but my push fails. Shouldn't being authenticated by gh configure an access token for the repo automatically?
for the record I had a convo with the maintainers and they said that this functionality actually exists in the CLI, it was just totally undocumented bc it has edge cases that aren't nice (eg if you have branch name conflicts) . so I guess we wait for them to document it and or to implement the custom gh PR push logic accounting for edge case.
I just came across this issue. The problem is that when you do git push, git doesn't know where to push your commits to.
I think this can be solved very cleanly if gh pr checkout set the upstream remote so that the commits go to the PR branch. Of course, git push will fail if the PR author hasn't allowed edits from maintainers, but that's expected behaviour.
Reacted by Johan Ljunggren, Dirk Avery, Jason R. Coombs, y7o4ka, Domenic Denicola, Maël Valais, Wish, Colin Anderson, Rain Sallow (/u/ta11ow), Ivo Jimenez and 26 more
FWIW, we do go to extra lengths to set up upstream configuration after gh pr checkout so that a plain git push will Just Work™ in a lot of cases. based on user feedback, this is not apparent to our users, since the pr checkout command doesn't tell you that it set it up, and we haven't documented it either.
however, when there are branch naming conflicts and the locally checked out branch is differently named than the "head" branch of a PR, git push without arguments will not work anymore.
I agree that a dedicated command that would handle all of those cases transparently would be a good idea.
@mislav 2 suggestions that might be easy to implement:
add a mention to https://cli.github.com/manual/gh_pr_checkout of how most people should be able to git push and have it "just work" (i personally havent even tried it since we chatted.. old habits die hard)
perhaps add a console message log the first or N or every time someone does a new gh pr checkout since many people are not going to read the docs
Reacted by Mislav Marohnić, Ivan, Brandon Kraft, Maël Valais, Joe Previte and Sukka
Has there been any update on this? I just spent an hour trying to make a silly change to an existing PR, frankly this isn't worth my time as an occasional contributor. People like me are actively discouraged from contributing.
At the very least can the github web interface be changed so that gh checkout is removed as an "easy" way of checking out a PR for editing, because obviously it is not.
If that cannot be done, can a clear help message be made as to what the recommended procedure is? I think I accidentally did the right thing somehow but I wouldn't be able to reproduce it next time.
The git push <remote> commands mentioned here do not work. The refspec portion must be specified because the local branch created by gh pr checkout does not match the name of the upstream branch. No remote tracking branch was set for me, either.
@nflaig that doesn’t work if the local and remote branch have different names - which happens if you already have a branch with that name (like master or main).
Reacted by Jason Axelson, Nico Flaig, Dennis Kieselhorst, Bernhard Kaindl, Sridhar Ratnakumar, Jonathan Hefner and LoveSy
It looks like pushing to remote/fork branch now just works using git
Checkout branch of PR
gh pr checkout <pr_number>
Then simply push
git push
Pulling works as well
git pull
This is great if you're checking out a PR that you haven't previously worked on -- if you first check out a branch, and then use gh pr create, your local branch is never associated with the upstream branch and git push won't work.
which makes git pushRemote -f work on branches that gh pr checkout creates, whether the pushRemote matches the branch name or not.
Be careful with your alias. The + in the refspec indicates that the source should overwrite the destination; effectively a force push. I did things this way in my scenario because I did a git rebase to clean up the PR commits.
Some users may not want force push semantics. In that case, a secondary version of that alias without the + in the refspec argument is desirable.
Then you should also make sure to always disable “maintainers can push", or they push something, you don't recognize and due to your alias simply overwrite
You do a force-push, so they overwrite anything. For pushing a rebase this is necessary, but if there were changes by the maintainer you did not fetch, you also overwrite those
Activity
mislav commentedon Oct 14, 2020
hub pushdoes nothing else but executegit push, since hub is a proxy forgit.You will find that this works if the maintainer has given you access to their PR:
gh pr checkout 123 # (do some commits…) git pushslorber commentedon Oct 14, 2020
Thanks @mislav , will try that.
Last time I tried that, afaik it pushed to upstream repo, not forked repo. I want to contribute to the fork, as the contributor should be able to continue working on his PR updated with my fixes.
Will double-check to see if your suggestion works.
slorber commentedon Oct 21, 2020
Hi @mislav
I wanted to improve this PR: facebook/docusaurus#3613
I run
gh pr checkout 3613and did my local commits.Then I tried the
git pushbut it didn't work. Only when I added remote repo URL did my commit end up showing in the PROnly the 2nd command was able to push to the PR:
So it looks like
git pushmay not be enough?Not sure what is happening with the 403 error either.
ochedruis a dev I worked with 2 years ago, on a totally different project 😅 he never contributed to Docusaurus in any way.Recently upgraded GH cli and had to login again just before, not sure it's related...
Any idea what is happening here? and why
ochedrushow up in the error message?I can try again on another PR soon if you need another case
mislav commentedon Oct 21, 2020
@slorber Do you prefer HTTPS or SSH protocol for git cloning/pushing? It looks like you prefer SSH, but gh defaults to HTTPS, as evident by it setting up a HTTPS push URL after
gh pr checkout.You can change the default with:
From the
Remote: permission to {REPO} denied to ochedruerror message, I suspect that the git credential helper for HTTPS repos had some credentials cached that belong to ochedru. See:bsiegel commentedon Oct 22, 2020
I'm having a very similar issue here with
ghand HTTPS remotes.I don't understand why
ghthinks I am logged in but my push fails. Shouldn't being authenticated byghconfigure an access token for the repo automatically?mislav commentedon Dec 9, 2020
@bsiegel Right now,
ghstill doesn't set your Git credentials even after you log in. You will need to configure git manually.However, we are working on a feature that will take care of this automatically for you: #1434
swyxio commentedon Dec 9, 2020
for the record I had a convo with the maintainers and they said that this functionality actually exists in the CLI, it was just totally undocumented bc it has edge cases that aren't nice (eg if you have branch name conflicts) . so I guess we wait for them to document it and or to implement the custom gh PR push logic accounting for edge case.
AshleyYakeley commentedon Jan 6, 2021
I just came across this issue. The problem is that when you do
git push, git doesn't know where to push your commits to.I think this can be solved very cleanly if
gh pr checkoutset the upstream remote so that the commits go to the PR branch. Of course,git pushwill fail if the PR author hasn't allowed edits from maintainers, but that's expected behaviour.swyxio commentedon Jan 6, 2021
FYI Ashley - this is what @mislav said:
mislav commentedon Jan 6, 2021
Precisely.
@AshleyYakeley You can check the configuration that GitHub CLI sets:
swyxio commentedon Jan 6, 2021
@mislav 2 suggestions that might be easy to implement:
git pushand have it "just work" (i personally havent even tried it since we chatted.. old habits die hard)gh pr checkoutsince many people are not going to read the docs16 remaining items
mthibaut commentedon May 10, 2023
Has there been any update on this? I just spent an hour trying to make a silly change to an existing PR, frankly this isn't worth my time as an occasional contributor. People like me are actively discouraged from contributing.
At the very least can the github web interface be changed so that gh checkout is removed as an "easy" way of checking out a PR for editing, because obviously it is not.
If that cannot be done, can a clear help message be made as to what the recommended procedure is? I think I accidentally did the right thing somehow but I wouldn't be able to reproduce it next time.
cubxxw commentedon May 11, 2023
good
rcdailey commentedon Jun 24, 2023
The
git push <remote>commands mentioned here do not work. The refspec portion must be specified because the local branch created bygh pr checkoutdoes not match the name of the upstream branch. No remote tracking branch was set for me, either.The command I used was:
The PR in question happened to be from the
masterbranch in the fork.This definitely needs first-class support, not just an alias or other workaround, in order to hide the plumbing from users.
ljharb commentedon Jun 29, 2023
@rcdailey thanks, that helped me craft this command:
which I then aliased in my gitconfig:
which makes
git pushRemote -fwork on branches thatgh pr checkoutcreates, whether the pushRemote matches the branch name or not.nflaig commentedon Jul 19, 2023
It looks like pushing to remote/fork branch now just works using git
Checkout branch of PR
Then simply push
Pulling works as well
ljharb commentedon Jul 19, 2023
@nflaig that doesn’t work if the local and remote branch have different names - which happens if you already have a branch with that name (like master or main).
taliastocks commentedon Feb 1, 2024
This is great if you're checking out a PR that you haven't previously worked on -- if you first check out a branch, and then use
gh pr create, your local branch is never associated with the upstream branch andgit pushwon't work.rcdailey commentedon Feb 1, 2024
Be careful with your alias. The
+in the refspec indicates that the source should overwrite the destination; effectively a force push. I did things this way in my scenario because I did agit rebaseto clean up the PR commits.Some users may not want force push semantics. In that case, a secondary version of that alias without the
+in the refspec argument is desirable.ljharb commentedon Feb 2, 2024
@rcdailey yes, that's intentional, i always am rebasing and thus force pushing when i'm pushing to a PR. good callout tho.
Vampire commentedon Feb 2, 2024
Then you should also make sure to always disable “maintainers can push", or they push something, you don't recognize and due to your alias simply overwrite
ljharb commentedon Feb 2, 2024
I’m not sure how those aliases could ever result in overwriting something.
Vampire commentedon Feb 2, 2024
You do a force-push, so they overwrite anything. For pushing a rebase this is necessary, but if there were changes by the maintainer you did not fetch, you also overwrite those
ljharb commentedon Feb 2, 2024
oh, sure. but the push and the PR will show the hash i overwrote so i can look at it :-)