github auto authentication with personal access tokens doesn't work
Asked Answered
M

2

6

I have followed the explanation here for setting up auto authentication of github on my CLI (on Linux, Ubuntu). In particular, I executed the command given here:

gh auth login

And then I answered Github.com, yes, HTTPS, and my authentication token to the prompts.

This seems to work: It states "Configured git protocol" and "Logged in as ...".

However, when I then write git clone <myrepo>, it asks me again for my username and password.

What am I doing wrong? My understanding was that the gh aut login command is supposed to prevent me from having to type the login data each time.

Menstruation answered 10/12, 2021 at 15:6 Comment(2)
@dan1st, I understand that, but the site I linked to states "GitHub CLI will automatically store your Git credentials for you when you choose HTTPS as your preferred protocol for Git operations". Therefore I am assuming that gh is doing some configuration of git behind the scenes, at least if it's working properly. If not, what should I do to log in?Menstruation
@dan1st, also note that the title of that page is ""Caching your GitHub credentials in Git.", and the motivation is: "Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client."Menstruation
T
15

found in the Github CLI Docs:

after you run gh auth login then run this command

gh auth setup-git
Turbulence answered 10/5, 2022 at 20:46 Comment(1)
This worked. What the hell GithubGoingover
P
8

In my case it was solved by adding at the end of the file ~/.gitconfig the following:

[credential "https://github.com"]
    helper = 
    helper = !/snap/bin/gh auth git-credential

Modify /snap/bin/gh with your real path (I've seen others having it in /usr/bin/gh)

Pursuivant answered 25/2, 2022 at 9:32 Comment(4)
Thank you for sharing this! I don't understand why the GH command doesn't do this, but this helped tremendously.Cant
worked for me (also installed using snap)Blinders
This works, thanks. what's the purpose of having the first line helper = pointing to nothing?Urinate
Thank you! Been struggling with this for a bit now! Also a note on this: you can run which gh to find your path to gh. Mine was /var/lib/snapd/snap/bin/ghLoosestrife

© 2022 - 2024 — McMap. All rights reserved.