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
bugSomething isn't workingcoreThis issue is not accepting PRs from outside contributorsdocsgh-reporelating to the gh repo commandhelp wantedContributions welcome
Hey @Shion1305, thanks for creating this and sorry four your trouble. For forked repos we expect a default to be set so that we know whether to work with the upstream or the fork. For example, most of the time when running pr create you would expect it to be created against the upstream.
However, your repo seems to be in an unusual state since it appears you only have one remote. How did you fork this repo and clone it onto your machine? Did you do anything with the remotes after cloning?
@williammartin Thanks for checking this issue!
I have forked the repo by fork button on the repository page, and cloned the folked repo by git clone ~
I haven't done any operation with git after that, so this is strange.
Right, I can explain then. Since you didn't use gh repo fork --clone, or gh repo clone, gh is recognising that it is working on a fork because when working with a repository, we resolve the network for it, which includes the parents of any remotes. If there is more than one remote (and no default), we require gh repo set-default to make sure that gh is interacting with the correct repository.
If you use gh repo clone, we set the default to the upstream:
➜ gh repo clone github-readme-stats
Cloning into 'github-readme-stats'...
remote: Enumerating objects: 7110, done.
remote: Counting objects: 100% (1112/1112), done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 7110 (delta 1084), reused 1058 (delta 1052), pack-reused 5998
Receiving objects: 100% (7110/7110), 3.56 MiB | 3.44 MiB/s, done.
Resolving deltas: 100% (4977/4977), done.
From https://github.com/anuraghazra/github-readme-stats
* [new branch] master -> upstream/master
* [new tag] v1.0.0 -> v1.0.0
! Repository anuraghazra/github-readme-stats set as the default repository. To learn more about the default repository, run: gh repo set-default --help
So you will need to run gh repo set-default and choose the remote that you want API requests to work against i.e.
➜ gh repo set-default --help
This command sets the default remote repository to use when querying the
GitHub API for the locally cloned repository.
gh uses the default repository for things like:
- viewing and creating pull requests
- viewing and creating issues
- viewing and creating releases
- working with GitHub Actions
- adding repository and environment secrets
Typically the upstream is the right choice. Functionally what this does is put an entry in your .git/config called gh-resolved. In the case of gh repo clone it sets the value to base on the upstream remote:
One improvement I can see is that when we do the automatic defaulting we include "To learn more about the default repository, run: gh repo set-default --help", which would probably be useful to include in your case as well.
About the current issue, do I have it right that the overall improvement being considered is the setting of the only remote (in the case of git clone clones) as the default repository, instead of prompting the user to manually set with gh repo set-default?
That sounds like a sensible change to me, but I'm also a bit curious about why this wasn't considered so far. Are there any consequences of automatically setting it? 🤔
About the current issue, do I have it right that the overall improvement being considered is the setting of the only remote (in the case of git clone clones) as the default repository, instead of prompting the user to manually set with gh repo set-default?
No, I'm not proposing a functional change here just a documentation one. There's a very real chance that even if you forked and cloned outside of gh, you still intend to work with the upstream repo, and I think it's just better to force the user to make a decision up front.
I am open to being convinced otherwise though, I was not on the team when the concept of default was introduced so I don't have any particularly strong feelings except a bit of Chesterton's Fence related anxiety. 😅
Labelling this help wanted with the action item being an update to ensure:
One improvement I can see is that when we do the automatic defaulting we include "To learn more about the default repository, run: gh repo set-default --help", which would probably be useful to include in your case as well.
bugSomething isn't workingcoreThis issue is not accepting PRs from outside contributorsdocsgh-reporelating to the gh repo commandhelp wantedContributions welcome
Activity
williammartin commentedon May 28, 2024
Hey @Shion1305, thanks for creating this and sorry four your trouble. For forked repos we expect a default to be set so that we know whether to work with the upstream or the fork. For example, most of the time when running
pr createyou would expect it to be created against the upstream.However, your repo seems to be in an unusual state since it appears you only have one remote. How did you fork this repo and clone it onto your machine? Did you do anything with the remotes after cloning?
Shion1305 commentedon May 28, 2024
@williammartin Thanks for checking this issue!
I have forked the repo by
forkbutton on the repository page, and cloned the folked repo bygit clone ~I haven't done any operation with git after that, so this is strange.
williammartin commentedon May 28, 2024
Right, I can explain then. Since you didn't use
gh repo fork --clone, orgh repo clone,ghis recognising that it is working on a fork because when working with a repository, we resolve the network for it, which includes the parents of any remotes. If there is more than one remote (and no default), we requiregh repo set-defaultto make sure thatghis interacting with the correct repository.If you use
gh repo clone, we set the default to the upstream:So you will need to run
gh repo set-defaultand choose the remote that you want API requests to work against i.e.Typically the upstream is the right choice. Functionally what this does is put an entry in your
.git/configcalledgh-resolved. In the case ofgh repo cloneit sets the value tobaseon the upstream remote:And in your case where you only have one remote, it sets the value to the location of the upstream repo:
One improvement I can see is that when we do the automatic defaulting we include "To learn more about the default repository, run: gh repo set-default --help", which would probably be useful to include in your case as well.
Hope this helps!
[-]`gh repo view` fails on folked repo[/-][+]`gh repo view` fails on forked repo[/+]arunsathiya commentedon May 29, 2024
I stumbled upon this issue when researching a different issue: After moving repo to a new org, pr create adds a new remote named fork every time.
About the current issue, do I have it right that the overall improvement being considered is the setting of the only remote (in the case of
git cloneclones) as the default repository, instead of prompting the user to manually set withgh repo set-default?That sounds like a sensible change to me, but I'm also a bit curious about why this wasn't considered so far. Are there any consequences of automatically setting it? 🤔
williammartin commentedon May 30, 2024
No, I'm not proposing a functional change here just a documentation one. There's a very real chance that even if you forked and cloned outside of
gh, you still intend to work with the upstream repo, and I think it's just better to force the user to make a decision up front.I am open to being convinced otherwise though, I was not on the team when the concept of
defaultwas introduced so I don't have any particularly strong feelings except a bit of Chesterton's Fence related anxiety. 😅williammartin commentedon May 31, 2024
Also relevant issue that I came across today which was surprising behaviour to me: #9152
williammartin commentedon Jun 4, 2024
Labelling this
help wantedwith the action item being an update to ensure:Is addressed.