Sitelet https://web.archive.org/web/20200911235029/https://github.com/cli/cli/issues/1605
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh : error adding remote: fatal: remote fork already exists. #1605

Open
bobbytreed opened this issue Aug 31, 2020 · 11 comments
Open

gh : error adding remote: fatal: remote fork already exists. #1605

bobbytreed opened this issue Aug 31, 2020 · 11 comments

Comments

@bobbytreed
Copy link

@bobbytreed bobbytreed commented Aug 31, 2020

When creating a PR using the command gh pr create --title "$($msg): Batch($i)" --body "$Body" -a $Assignee

GH complains as follows: gh : error adding remote: fatal: remote fork already exists.

. . . I know the fork already exists. I forked it (6 months ago). Is gh pr create assuming I need to delete all my forks for each pr creation? Why not just use the fork that I just pushed to?

gh version 0.11.1 (2020-07-28)
https://github.com/cli/cli/releases/tag/v0.11.1

@bobbytreed bobbytreed added the bug label Aug 31, 2020
@mislav
Copy link
Member

@mislav mislav commented Aug 31, 2020 •

@bobbytreed Sorry for the nuisance!

Just to double-check: if you check git remote -v, does the existing fork remote have a valid GitHub.com URL? Is the URL https: or of a different protocol? Does that URL take you to a repository your user account has push access to?

I'm confused why you are seeing the error because we already try to detect a fork you have push access to, and if one exists, we automatically push to it. I don't understand why gh is trying to add yet another fork remote; it must be some bug. Thank you for reporting!

Tip: you can set DEBUG=1 or DEBUG=api (more verbose) before any gh command to see verbose logging output 👍

@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Aug 31, 2020

It initially pointed to an https url even though repo was cloned with ssh (another bug already created ). Problem is that it threw a credential exception with http because the org requires SAML. I updated forks to use ssh, and still get this error.
I'll add debug output when I get back to computer

@mislav
Copy link
Member

@mislav mislav commented Aug 31, 2020

@bobbytreed Thanks for looking into this! BTW you can configure GitHub CLI to default to SSH-style URLs everywhere:

gh config set git_protocol ssh
@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Aug 31, 2020

How would I set DEBUG to 1? PowerShell doesn't like unnamed variables that are not preceded by $ signs

@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Aug 31, 2020

Also, did change the ssh flag. Thanks. Still getting error though.

gh : error adding remote: fatal: remote fork already exists.
At line:1 char:1

  • gh pr create --title "$($msg): Batch($i)" --body "$Body" -a $Assignee
  •   + CategoryInfo          : NotSpecified: (error adding re...already exists.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

git: exit status 128

@mislav
Copy link
Member

@mislav mislav commented Aug 31, 2020

@bobbytreed Apologies, my instructions were not meant for PowerShell.

Something like this should work for PowerShell:

> $env:DEBUG="1"
> gh pr create ...
@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Aug 31, 2020

[git status --porcelain]
[git -c log.ShowSignature=false log --pretty=format:%H,%s --cherry upstream/master...fqdnrepair-0]
[git -c log.ShowSignature=false show -s --pretty=format:%b 30e8d7d8c31ce000bad36d9355a7ce4cde79fd73]

  • Request at 2020-08-31 15:15:06.7301373 -0400 EDT m=+1.381074501
  • Request to https://api.github.com/graphql
  • Request took 126.041ms
    [git remote add -f fork https://github.com/bobbytreed/***********]
    error adding remote: fatal: remote fork already exists.
    git: exit status 128

Even more worrisome that its trying to create it under that location.

fork git@github.com:DCtheGeek/*********** (fetch)
fork git@github.com:DCtheGeek/*********** (push)

so why is it inventing an http hook to reach out to that is not specified in any remote?

@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Aug 31, 2020

There are multiple SSH users on this machine, so I know that can cause confusion, but still I would think gh.exe would go by the remotes to check for fork locations

@mislav
Copy link
Member

@mislav mislav commented Sep 1, 2020 •

@bobbytreed What would your preferred behavior for gh be here, ideally?

When you do gh pr create, you are authenticated as bobbytreed. The command auto-creates a fork under that user to push the code to. However, there is already a fork remote to a repository owned by DCTheGeek; and I suspect that bobbytreed does not have the rights to push to that repository.

You can try to work around this by ensuring that the current branch is fully pushed to one of your git remotes before running gh pr create.

gh does not yet have support for multiple logged in users #326

@bobbytreed
Copy link
Author

@bobbytreed bobbytreed commented Sep 1, 2020

I understand your logic, but how am I authenticated as bobbytreed? The GITHUB_TOKEN, and GITHUB_OAUTHTOKEN, and SSH Key are all from DCtheGeek. How is it determining that I am bobbytreed?

I want to know which method gh is using to determine who I am? Because in the schema I just described. It is very confusing to determine how it figures out who I am, and furthermore, gh creates a remote fork, but then somehow ignores it?

gh created the remote fork pointing to https://github.com/bobbytreed. So I changed the remote and tried the command again, but it still attempted to create it under my account. Why would gh bother to create something that it would ignore?

Understanding the authentication process and where the OAUTH_TOKEN, SSH key,and GITHUB_TOKEN come into play will help me make sure that I am on the right track.

@mislav
Copy link
Member

@mislav mislav commented Sep 1, 2020 •

how am I authenticated as bobbytreed? The GITHUB_TOKEN, and GITHUB_OAUTHTOKEN, and SSH Key are all from DCtheGeek.

gh first reads the token from GITHUB_TOKEN environment variable, if one exists, and then from credentials saved to ~/.config/gh/hosts.yml after you go through an authentication flow for the first time. It does not respect GITHUB_OAUTHTOKEN, OAUTH_TOKEN, nor SSH key configuration. If you have multiple users set up via SSH config, gh will not switch user accounts accordingly.

You can check your currently authenticated user with: gh api user.

The state of authentication right now is indeed confusing! In the upcoming release this week, verifying the status of your authentication will be easier via the dedicated gh auth status command #1495. We will also have better documentation for environment variables #1370.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.