Home > Software engineering >  Github prompts for username and password despite git credentials being stored in .gitconfig
Github prompts for username and password despite git credentials being stored in .gitconfig

Time:11-19

When I run git push on a repository that I own I get prompted for username and password.

╭─[email protected] ~/workspace/blah
╰─➤  git push
Username for 'https://github.com/acarrillo2/dotfiles.git': acarrillo2
Password for 'https://[email protected]/acarrillo2/dotfiles.git':

However when I run git config --list I see github.user and github.token get printed out.

...
user.name=Austin Carrillo
[email protected]
github.user=acarrillo2
github.token=SUPER_SECRET

Looking at the docs for gh: https://cli.github.com/manual/

It appears this should work but just to be sure I also added my token as an environmental variable and it is printed out when I use printenv:

...
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
GH_TOKEN=SUPER_SECRET

Is there somewhere else I should be storing these?

Note: I am not using any virtual environments.

I would expect that storing this value in my gitconfig OR my environmental variable would do the trick.

I even tried running the below command and I still get prompted for username and password:

╭─austin@laptop ~/workspace/blah
╰─➤  gh auth login
? What account do you want to log into? GitHub.com
The value of the GH_TOKEN environment variable is being used for authentication.
To have GitHub CLI store credentials instead, first clear the value from the environment.

Still get prompted for username and password.

CodePudding user response:

Check the value of git config --global credential.helper.

If empty, set it to 'manager', and install the latest GCM (Git Credential Manager), for MacOS

The next prompt will then store your credentials (GitHub user account and GitHub token) to said credential manager.

After that, you should not be prompted anymore for your credentials.

CodePudding user response:

Git doesn't use your Git config for credentials because that's insecure. The gh command-line tool is not Git and doesn't work the same way. In fact, Git knows nothing specifically about GitHub and doesn't use github.* keys at all.

You'll want to use a credential manager to store your credentials. If you want to do that using the environment, you can do that using the technique outlined in the Git FAQ. Otherwise, you can set credential.helper to manager on Windows, osxkeychain on macOS, or libsecret on Linux. (On Debian and Ubuntu, you must copy /usr/share/doc/git/contrib/credential/libsecret and build the credential helper with make, then install the binary in your PATH.)

Once you've done that, next time you push or pull, you should be prompted for your password. Enter your username for your username, and the token for the password. Note that you won't see any echo of characters on the screen. Then, because you're using a credential helper, Git will save the username and password in the credential store you selected and it should be used automatically in the future.

  • Related