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
$ gh repo fork- Forking org/repo...✓ Created fork jglick/repo? Would you like to add a remote for the fork? Yes✓ Renamed origin remote to upstream✓ Added remote origin
$ git remote -vorigin [email protected]:jglick/repo.git (fetch)origin [email protected]:jglick/repo.git (push)upstream ssh://[email protected]/org/repo.git (fetch)upstream ssh://[email protected]/org/repo.git (push)
Expected vs actual behavior
I wanted to see
$ gh repo fork- Forking org/repo...✓ Created fork jglick/repo? Would you like to add a remote for the fork? Yes✓ Added remote fork
$ git remote -vfork [email protected]:jglick/repo.git (fetch)fork [email protected]:jglick/repo.git (push)origin ssh://[email protected]/org/repo.git (fetch)origin ssh://[email protected]/org/repo.git (push)
For context and discussion leading to the current behavior, see #582 (/cc @cben).
I do agree that renaming the remotes is undesirable, but I think the main problem here is that the user is not told about the upcoming renaming in advance.
So instead of being told of the renaming only after the fact, as is the current behavior:
$ gh repo fork- Forking someorg/foobar...✓ Created fork myusername/foobar? Would you like to add a remote for the fork? Yes✓ Renamed origin remote to upstream✓ Added remote origin
...I'd like to at least be informed of the impending rename; something like:
$ gh repo fork- Forking someorg/foobar...✓ Created fork myusername/foobar? Would you like to add a remote for the fork? Yes? Would you like to rename the current 'origin' remote to 'upstream'? Yes✓ Renamed origin remote to upstream✓ Added remote origin
...with the following alternative outcome, should I pick "no" in the second prompt:
$ gh repo fork- Forking someorg/foobar...✓ Created fork myusername/foobar? Would you like to add a remote for the fork? Yes? Would you like to rename the current 'origin' remote to 'upstream'? No✓ Added remote fork # Or myusername
Reacted by Mislav Marohnić, Jesse Glick and Simon Li
Can we please have a config option to control this behaviour.
I want the behaviour I currently have with hub fork, i.e. it leaves origin unchanged and adds the remote using the name of the organization/user that the fork was created in
@dfireBird Sure, I'd like us to address this is the next feature release! A PR that adds a prompt would be welcome. I'm also thinking that something like a --remote-name flag for automation would also be great.
I don't know go yet! So I just copied and pasted previous code from the repository for the prompt and I had some itty hack I did! I will make sure to correct it and open a PR.
@vilmibm thanks for adopting and merging #1882! It's definitely a large step in the right direction, but I actually find the UX implemented there a little cumbersome (requiring the user to repeat the command, this time passing the --remote-name="fork"):
Couldn't the first invocation offer the option to provide the fork name interactively, like this?
Scenario where the user accepts renaming origin to upstream:
$ gh repo fork- Forking someorg/foobar...✓ Created fork myusername/foobar? Would you like to add a remote for the fork? Yes! A remote called 'origin' already exists? Would you like to rename the current 'origin' remote to 'upstream'? Yes✓ Renamed 'origin' remote to 'upstream'✓ Added remote 'origin'
Scenario where the user rejects renaming origin to upstream (same sequence except for the last 3 lines):
$ gh repo fork- Forking someorg/foobar...✓ Created fork myusername/foobar? Would you like to add a remote for the fork? Yes! A remote called 'origin' already exists? Would you like to rename the current 'origin' remote to 'upstream'? No? What should be the remote name for the fork? fork✓ Added remote 'fork'
Is this something that could be tracked in a separate issue, or are you against that kind of behavior in principle?
Sure, I am not advocating for removal of the flag :) In fact, I will probably also do something similar to your alias, since I'm used to that workflow thanks to hub :) but for people who don't yet have strong preferences, the default experience could be more ergonomic. In other words, we could have both a flag and interactive prompts if the flag isn't passed, rather than an error requesting to run the command again.
(On a related note, it might be a good idea to allow configuring a default remote name for forks via gh config, so that one doesn't have to override the default fork subcommand with an alias.)
@waldyrious thanks for the feedback! In general we're trying to find the correct balance of prompting + magic + maintainability. We felt that implicit renaming was too much magic but more prompting == more difficult tests and less maintainable code. It's possible we'll want prompts back, here, but for now wanted to err on the side of simpler code.
I'll say that while friendly prompts and a major goal of gh we are trying to be more careful with them until we have a better framework for testing them and, possibly, new primitives for prompts that we're more comfortable maintaining.
Thanks for the response. I'll be looking forward to improved maintainability of prompt-based code, as those are one of the key aspects that make gh work so well IMO, and would definitely improve this flow, in particular.
In case this helps others who come across this thread: until #8659 is addressed (which would allow gh fork to set the default repository), I have modified my fork alias in ~/.config/gh/config.yml to run gh repo set-default in addition to gh repo fork:
This way I don't need to be pestered by the "No default remote repository has been set for this directory" error whenever I try to open a PR in a new repository :)
Activity
AliabbasMerchant commentedon May 1, 2020
Can we introduce a flag for asking the remote name for the fork?
If the user specifies the remote name, well and good.
If not:
waldyrious commentedon May 10, 2020
For context and discussion leading to the current behavior, see #582 (/cc @cben).
I do agree that renaming the remotes is undesirable, but I think the main problem here is that the user is not told about the upcoming renaming in advance.
So instead of being told of the renaming only after the fact, as is the current behavior:
...I'd like to at least be informed of the impending rename; something like:
...with the following alternative outcome, should I pick "no" in the second prompt:
stephenc commentedon Sep 4, 2020
Can we please have a config option to control this behaviour.
I want the behaviour I currently have with
hub fork, i.e. it leaves origin unchanged and adds the remote using the name of the organization/user that the fork was created instephenc commentedon Sep 4, 2020
Aside: Ha! Just noticed the issue creator is a fellow ☁️ 🐝
🤣
jglick commentedon Sep 8, 2020
Nicer workaround:
Use as:
dfireBird commentedon Sep 20, 2020
I was using a offline fork with aforementioned feature with a prompt for sometime. If it's okay can I open a PR?
mislav commentedon Sep 21, 2020
@dfireBird Sure, I'd like us to address this is the next feature release! A PR that adds a prompt would be welcome. I'm also thinking that something like a
--remote-nameflag for automation would also be great.dfireBird commentedon Sep 21, 2020
I don't know go yet! So I just copied and pasted previous code from the repository for the prompt and I had some itty hack I did! I will make sure to correct it and open a PR.
waldyrious commentedon Jan 21, 2021
@vilmibm thanks for adopting and merging #1882! It's definitely a large step in the right direction, but I actually find the UX implemented there a little cumbersome (requiring the user to repeat the command, this time passing the
--remote-name="fork"):Couldn't the first invocation offer the option to provide the fork name interactively, like this?
Scenario where the user accepts renaming origin to upstream:
Scenario where the user rejects renaming origin to upstream (same sequence except for the last 3 lines):
Is this something that could be tracked in a separate issue, or are you against that kind of behavior in principle?
cben commentedon Jan 21, 2021
I actually like it being a flag, because now I can
and not deal with any prompts. ❤️
waldyrious commentedon Jan 21, 2021
Sure, I am not advocating for removal of the flag :) In fact, I will probably also do something similar to your alias, since I'm used to that workflow thanks to
hub:) but for people who don't yet have strong preferences, the default experience could be more ergonomic. In other words, we could have both a flag and interactive prompts if the flag isn't passed, rather than an error requesting to run the command again.(On a related note, it might be a good idea to allow configuring a default remote name for forks via gh config, so that one doesn't have to override the default
forksubcommand with an alias.)vilmibm commentedon Jan 21, 2021
@waldyrious thanks for the feedback! In general we're trying to find the correct balance of prompting + magic + maintainability. We felt that implicit renaming was too much magic but more prompting == more difficult tests and less maintainable code. It's possible we'll want prompts back, here, but for now wanted to err on the side of simpler code.
I'll say that while friendly prompts and a major goal of
ghwe are trying to be more careful with them until we have a better framework for testing them and, possibly, new primitives for prompts that we're more comfortable maintaining.waldyrious commentedon Jan 21, 2021
Thanks for the response. I'll be looking forward to improved maintainability of prompt-based code, as those are one of the key aspects that make
ghwork so well IMO, and would definitely improve this flow, in particular.jglick commentedon Feb 22, 2021
After #2982 revised my workaround #847 (comment) to be similar to #847 (comment):
waldyrious commentedon Sep 3, 2026
In case this helps others who come across this thread: until #8659 is addressed (which would allow
gh forkto set the default repository), I have modified myforkalias in~/.config/gh/config.ymlto rungh repo set-defaultin addition togh repo fork:This way I don't need to be pestered by the "No default remote repository has been set for this directory" error whenever I try to open a PR in a new repository :)