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
{{ message }}
Repository navigation
Update remote naming when using gh repo fork to use origin & upstream #582
When forking a repo with gh repo fork, the remote is named "fork".
Instead I'd prefer this to use the upstream's namespace (username under which the fork lives), which, for a fork created by me, would be "waldyrious".
That would make the list of remotes more self-descriptive, and would allow cloning multiple forks of the same repo without naming conflicts or using e.g. counters like "fork-1", etc.
Note: the proposed solution is what hub does.
Reacted by Sindre Sorhus, Thomas Eizinger and Beni Cherniavsky-Paskin
changed the title [-]gh repo fork should use the fork's username as remote rather than "fork"[/-][+]`gh repo fork` should use the fork's username as remote[/+]on Mar 4, 2020
I agree that simply "fork" isn't the best name, partly because it's ambiguous (as you point out, there may be multiple remotes each pointing to a fork). But I was also not perfectly happy with hub's default either, mainly for scripting: after issuing a hub fork operation, you would have to know your username to be able to generate a git push <remote> <branch> command. Later hub received the --remote-name option, which made it better for scripting so that you can pick a static name instead of having the remote be a moving target, but I still don't think the default is all that great.
Upon forking a repo, I'm leaning to naming your fork "origin" while renaming the other remote to "upstream". This goes along with "triangular workflow" that some in the git community are following and that GitHub generally encourages.
In the end, any default we choose will likely disappoint someone, and we're not yet ready to add a ton of configuration options for this either. So we're going to give this a lot of thought and update with new ideas/approaches.
changed the title [-]`gh repo fork` should use the fork's username as remote[/-][+]Update remote naming when using `gh repo fork` to use origin & upstream[/+]on Mar 9, 2020
We discussed this quite a bit this morning, and decided that we're going to follow the documented GitHub model here for remote naming of fork vs. parent.
When someone creates a fork, we'll use the following naming scheme:
Fork: origin
Parent: upstream
This sometimes means that the parent repo's remote will be renamed, many times from origin, to the new name, upstream.
As @mislav mentioned, we know this isn't going to satisfy everyone, but we think it's a reasonable default and anything we do will likely not fit with everyone's preference.
Thanks for considering this. I wish you had picked hub's approach, rather than one that will require renaming remotes and produce ambiguous remote names, but I trust that you weighted pros and cons of each approach.
I have maybe hundreds of clone directories (on several machines) using hub's naming. As gh doesn't cover (and doesn't plan to cover?) all of hub's functionality, I was thinking to use both, gradually leaning on gh more and more.
But if they use different naming, I'll get a mixture of conventions, which is a recipe for me making mistakes.
If gh starts renaming existing remotes, it's (1) surprising 👎 — in a sequence of git push origin branch1; gh pr create; git push origin branch2 I don't expect origin to change meaning mid-way! (2) accelerates me getting a mixture of conventions.
When renaming existing remotes, please make it print an attention-grabbing message.
Consider a command for explictily normalizing remotes (and do nothing else). Good for massive switch-over to new convention.
I really loved hub's naming, despite most my coworkers preferring upstream + origin. Let me try to see why, and how new scheme compares.
History dependence
There are three and a half common scenarios:
Cloned upstream project as origin, never modified it.
Cloned upstream project as origin. Later decided to contribute, created a fork, adding a remote.
Directly cloned my fork as origin. Later adding a remote for upstream.
Push / send PR to my own repo. Only 1 remote, probably called origin.
It's is nasty that (1), (2) vs (3) result in origin meaning different things :-(
I felt that hub solved this problem, but did it really? Not exactly.
It's mainly that any tool-supported convention encourages consistency! I just learnt to avoid (2) EDIT: avoid (3) 😄.
However, hub fork did actively help, in several ways! First, the habit of hub fork rather than doing it in the UI, gave me a "correctly named" remote. Second, hub fork is idempotent, effectively alias to hub remote add cben if fork already exists. This helped me avoid (3) by making it just-as-easy to always clone upstream, then add myself. (Also removes any need to remember whether I'd already forked 😎)
For repeated contributors, I like hub add remote foo adding their fork as foo.
I can have remotes origin (main repo), cben (me), foo, bar. This is symmetric and nice :-)
Having remotes upstream, fork (me), foo, bar would be less symmetric :-\
(and as I said I enjoyed hub remote add cben for myself, although hub fork is shorter)
Scripting / shell safety
I work on projects where I have commit access to main repo, and sometimes collaborators' forks ("allow commits by maintainers" is nice!), but we want to always make PRs.
I taught myself to type git push REMOTE, not just git push. Especially with -f 😅. But is remote name unambiguous?
I have a script that boils down to git citool && git push cben.
Pushing to a remote named cben is never dangerous 👷♂️. If it exists, in scenarios (2), (3) it's my fork. In scenario (4) I might want to be careful to open PRs and never push master directly, but my remote will be origin not cben (this relies on currently not consistently naming it!)
Doing git push fork would be just as safe 👍
Doing get push origin is risky! ⚠️ It might be my fork with new convention — but it risks being main repo or collaborators' fork, if I wasn't careful at git clone time...
I especially don't want to aquire the habit of git push origin -f during normal contribution rebasing my PRs! 🙅♂️
Remote names are also important, even more, in branch refs.
They define what origin/master means in commands!
I type git rebase -i origin/master all the time. Also git diff origin/master etc...
Would upstream/master work just as well? Mostly, yes.
However, there is the case of (1) where I didn't expect to contribute, used off-the-shelf git clone and got it named origin...
(Active renaming would mitigate this a bit 👍)
Suggestion: upstream + fork.
origin is inherently ambiguous. Globally it means "whatever I used in git clone". Now it might mean "whether I'd used hub or gh in this directory".
Now you'll have a tool that knows how to query Github and [usually] figure out when it's dealing with main repo vs forks, which is an improvement 👏
=> Consider avoiding origin altogether and renaming to unambiguous upstream vs fork. (Or upstream vs username.)
P.S. ❤️ I'll use this opportunity to say Thank you — for hub, for gh, and for GitHub at large :)
@waldyrious@cben Thank you for your input! It's a good point to consider the potential surprising factor of swapping remote names in case gh pr create creates a fork. I also agree that remote renaming would be a potentially surprising side-effect of that command and that we should try to avoid it.
P.S. ❤️ I'll use this opportunity to say Thank you — for hub, for gh, and for GitHub at large :)
Note that this document seems to be presuming that the workflow is something like
navigate to someone else’s (e.g., an org’s) repo
click the Fork button
use the suggested commands under Clone to, e.g., git clone https://github.com/myacct/repo
do work (preferably on a topic branch)
file PRs, whatever
optionally, at some point, add an upstream remote so you can merge in upstream master
whereas the command under discussion here invites a workflow more like
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
[-]gh repo fork should use the fork's username as remote rather than "fork"[/-][+]`gh repo fork` should use the fork's username as remote[/+]mislav commentedon Mar 4, 2020
Thanks for adding your thoughts!
I agree that simply "fork" isn't the best name, partly because it's ambiguous (as you point out, there may be multiple remotes each pointing to a fork). But I was also not perfectly happy with hub's default either, mainly for scripting: after issuing a
hub forkoperation, you would have to know your username to be able to generate agit push <remote> <branch>command. Later hub received the--remote-nameoption, which made it better for scripting so that you can pick a static name instead of having the remote be a moving target, but I still don't think the default is all that great.Upon forking a repo, I'm leaning to naming your fork "origin" while renaming the other remote to "upstream". This goes along with "triangular workflow" that some in the git community are following and that GitHub generally encourages.
In the end, any default we choose will likely disappoint someone, and we're not yet ready to add a ton of configuration options for this either. So we're going to give this a lot of thought and update with new ideas/approaches.
[-]`gh repo fork` should use the fork's username as remote[/-][+]Update remote naming when using `gh repo fork` to use origin & upstream[/+]billygriffin commentedon Mar 9, 2020
We discussed this quite a bit this morning, and decided that we're going to follow the documented GitHub model here for remote naming of fork vs. parent.
When someone creates a fork, we'll use the following naming scheme:
Fork:
originParent:
upstreamThis sometimes means that the parent repo's remote will be renamed, many times from
origin, to the new name,upstream.As @mislav mentioned, we know this isn't going to satisfy everyone, but we think it's a reasonable default and anything we do will likely not fit with everyone's preference.
waldyrious commentedon Mar 10, 2020
😢
Thanks for considering this. I wish you had picked hub's approach, rather than one that will require renaming remotes and produce ambiguous remote names, but I trust that you weighted pros and cons of each approach.
cben commentedon Mar 23, 2020
Interoperability angle:
I have maybe hundreds of clone directories (on several machines) using hub's naming. As
ghdoesn't cover (and doesn't plan to cover?) all of hub's functionality, I was thinking to use both, gradually leaning onghmore and more.But if they use different naming, I'll get a mixture of conventions, which is a recipe for me making mistakes.
If
ghstarts renaming existing remotes, it's (1) surprising 👎 — in a sequence ofgit push origin branch1; gh pr create; git push origin branch2I don't expectoriginto change meaning mid-way! (2) accelerates me getting a mixture of conventions.When renaming existing remotes, please make it print an attention-grabbing message.
Consider a command for explictily normalizing remotes (and do nothing else). Good for massive switch-over to new convention.
I really loved hub's naming, despite most my coworkers preferring
upstream+origin. Let me try to see why, and how new scheme compares.History dependence
There are three and a half common scenarios:
origin, never modified it.origin. Later decided to contribute, created a fork, adding a remote.origin. Later adding a remote for upstream.origin.It's is nasty that (1), (2) vs (3) result in
originmeaning different things :-(I felt that
hubsolved this problem, but did it really? Not exactly.It's mainly that any tool-supported convention encourages consistency! I just learnt to
avoid (2)EDIT: avoid (3) 😄.However,
hub forkdid actively help, in several ways! First, the habit ofhub forkrather than doing it in the UI, gave me a "correctly named" remote. Second,hub forkis idempotent, effectively alias tohub remote add cbenif fork already exists. This helped me avoid (3) by making it just-as-easy to always clone upstream, then add myself. (Also removes any need to remember whether I'd already forked 😎)#620 will be innovative and maybe even better 👍
Symmetry with naming of other's forks
For repeated contributors, I like
hub add remote fooadding their fork asfoo.I can have remotes
origin(main repo),cben(me),foo,bar. This is symmetric and nice :-)Having remotes
upstream,fork(me),foo,barwould be less symmetric :-\(and as I said I enjoyed
hub remote add cbenfor myself, althoughhub forkis shorter)Scripting / shell safety
I work on projects where I have commit access to main repo, and sometimes collaborators' forks ("allow commits by maintainers" is nice!), but we want to always make PRs.
I taught myself to type
git push REMOTE, not justgit push. Especially with-f😅. But is remote name unambiguous?I have a script that boils down to
git citool && git push cben.Pushing to a remote named
cbenis never dangerous 👷♂️. If it exists, in scenarios (2), (3) it's my fork. In scenario (4) I might want to be careful to open PRs and never pushmasterdirectly, but my remote will beoriginnotcben(this relies on currently not consistently naming it!)Doing
git push forkwould be just as safe 👍Doing⚠️ It might be my fork with new convention — but it risks being main repo or collaborators' fork, if I wasn't careful at
get push originis risky!git clonetime...I especially don't want to aquire the habit of
git push origin -fduring normal contribution rebasing my PRs! 🙅♂️Remote names are also important, even more, in branch refs.
They define what
origin/mastermeans in commands!I type
git rebase -i origin/masterall the time. Alsogit diff origin/masteretc...Would
upstream/masterwork just as well? Mostly, yes.However, there is the case of (1) where I didn't expect to contribute, used off-the-shelf
git cloneand got it namedorigin...(Active renaming would mitigate this a bit 👍)
Suggestion:
upstream+fork.originis inherently ambiguous. Globally it means "whatever I used ingit clone". Now it might mean "whether I'd usedhuborghin this directory".Now you'll have a tool that knows how to query Github and [usually] figure out when it's dealing with main repo vs forks, which is an improvement 👏
=> Consider avoiding
originaltogether and renaming to unambiguousupstreamvsfork. (Orupstreamvs username.)P.S. ❤️ I'll use this opportunity to say Thank you — for
hub, forgh, and for GitHub at large :)mislav commentedon Mar 24, 2020
@waldyrious @cben Thank you for your input! It's a good point to consider the potential surprising factor of swapping remote names in case
gh pr createcreates a fork. I also agree that remote renaming would be a potentially surprising side-effect of that command and that we should try to avoid it.Yay☺️
jglick commentedon May 13, 2020
Note that this document seems to be presuming that the workflow is something like
git clone https://github.com/myacct/repoupstreamremote so you can merge in upstreammasterwhereas the command under discussion here invites a workflow more like
gh repo clone someorg/repogh repo forkgh pr creategit pull origin master:masterdepending on the remote name (Unwanted remote naming after gh repo fork #847 (comment))Push to origin as gh fork renames original origin to upstream
daurnimator commentedon Jan 1, 2022
Is there some way to opt-out of this behaviour by default? (e.g. in config file?)
jglick commentedon Jan 3, 2022
@daurnimator I just use #847 (comment) FWIW.
wookayin commentedon Oct 10, 2023
#847 (comment) says:
FYI this will update the config into
~/.config/gh/config.ymlwaldyrious commentedon Sep 3, 2026
For completeness' sake, I'm also copying the comment I just added there: