Skip to content

gh auth setup-git requires a login #8521

Description

@jtnord

Describe the bug

gh auth setup-git should be used to configure the github credential helper (basically git config --global credential.https://github.com.helper !'$PATH_TO_GH.EXE' auth git-credential however the command fails with You are not logged into any GitHub hosts. Run gh auth login to authenticate.

as the command is purely configuring git there should be no requirement for it to be logged in. this causes pain where the command is being run to pre-setup developer environments but leaves the login to the user at a later date (when it is needed)

gh version 2.40.1 (2023-12-13)
https://github.com/cli/cli/releases/tag/v2.40.1

Steps to reproduce the behavior

  1. on a clean machine download and install but do not configure git and gh
  2. gh auth setup-git --hostname github.com
  3. git config --global -l

Expected vs actual behavior

the command in step 2 runs without error
the command in step 3 shows that the helper has been added

Actual behaviour is the second command fails

> gh auth setup-git --hostname github.com
You are not logged into any GitHub hosts. Run gh auth login to authenticate.

Logs

Activity

  1. samcoe commented on Jan 4, 2024

    @samcoe
    Contributor

    @jtnord Thanks for writing in. I think you make a good point in that allowing auth setup-git to be run before authenticating is useful for doing pre-setup of developer environments. It should be simple enough to add the skipAuthCheck annotation to the auth setup-git command, going to open this up for contributions.

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    gh-authrelating to the gh auth command
    and removed on Jan 4, 2024
  3. mustafateke535 commented on Jan 4, 2024

    @mustafateke535
  4. williammartin commented on Jan 5, 2024

    @williammartin
    Member

    @samcoe I don't think this is related to skipAuthCheck but that the command itself asserts this?

    I agree that if you provide the hostname flag that this check doesn't need to be enforced.

    I think if you were to run it with no logged in hosts it should either continue to do what it does, or default to github.com (which is essentially the only known host). In the absence of a good reason to default it, I'd say leave it as it is.

  5. samcoe commented on Jan 5, 2024

    @samcoe
    Contributor

    @williammartin Thanks for the correction, 🤦, I did not actually look at the code and just assumed it was using the same skipAuthCheck mechanism other commands are using.

    I concur that the auth check should only be skipped if the hostname flag is provided.

  6. williammartin commented on Jan 9, 2024

    @williammartin
    Member

    @jtnord @samcoe on reviewing this a bit more, I wonder whether it might be better to provide a --force flag in combination with `--hostname"?

    There's still some advantage to the current behaviour where running setup-git --hostname github.con provides a useful error. In the case where you really, really want to add a credential helper for an unknown host, then you can opt in to --force. WDYT?

  7. samcoe commented on Jan 9, 2024

    @samcoe
    Contributor

    @williammartin I think that is a good suggestion. I am on board with that approach 👍

  8. williammartin commented on Jan 18, 2024

    @williammartin
    Member

    This has been merged into trunk if you'd like to try it. Our release cadence is roughly every two weeks and we released yesterday. It may go out next week at the earliest. Thanks everyone for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-authrelating to the gh auth commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions