Skip to content

Newbie problems with gh auth login --with-token #10922

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

Open
halcwb opened this issue May 3, 2025 · 1 comment
Open

Newbie problems with gh auth login --with-token #10922

halcwb opened this issue May 3, 2025 · 1 comment
Labels

Comments

@halcwb
Copy link

halcwb commented May 3, 2025

I was lucky to find the below comment. But after installing a fresh git on my new mac, I really struggled to get authentication working. I first tried the interactive gh auth login, but that didn't work after pasting my token. Then I tried the explicit gh auth login --with-token, pasting the token. Also, doesn't work as the token has to be piped from a file. But then still no luck. Finally ran the below commands.

This is all very confusing and undocumented. I know a lot of people are struggling with github authentication. Feel that this could be more user friendly/better documented.

@atsalolikhin-spokeo It looks like you are successfully logged in to gh with the token from your GITHUB_TOKEN environment variable, but that doesn't yet guarantee that git operations (such as git clone) are authenticated using the same mechanism.

Try doing this (if on a unix-like system):


git config --global credential.https://github.com.helper ''

git config --global --add credential.https://github.com.helper "\!$(which gh) auth git-credential"

This sets up gh as the credential helper for git operations. In fact, this is what GitHub CLI would do during normal gh auth login flow, which for you was skipped because you had already set up GITHUB_TOKEN via your environment variables. Since your environment contains signs of manual setup, we assume that you want to go the full manual route and not have gh intervene.

We plan to improve authentication for git commands spawned from within GitHub CLI: #2944

but that still won't cover regular git operations for people who have skipped gh auth login.

Originally posted by @mislav in #3369

@cliAutomation cliAutomation added the needs-triage needs to be reviewed label May 3, 2025
@williammartin
Copy link
Member

Hey @halcwb,

If you are using a credential helper that isn't gh, when you go through gh auth login, after being prompted for protocol choice, you will be prompted "Authenticate Git with your GitHub credentials?", which will give the obtained token to your credential helper.

On the other hand, if you run gh auth setup-git then gh will configure itself as a git credential helper and then any token you obtain via auth login (or via GH_TOKEN) will also be used.

Do you think it would help to include some of this information directly in the auth login --help? It seems reasonable that people would want to understand this from the entrypoint of auth login. Thanks.

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

No branches or pull requests

3 participants