You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
git asks for password despite authentication with gh #4351
Any git command that needs credentials asks for my password, despite being logged in with gh auth login. If I re-authenticate, git wont ask for my password for a few minutes, but will eventually revert to asking for my password again.
gh version 2.0.0
CentOS Linux release 7.5.1804 (Core)
git version 2.30.1
github.com
Logged in to github.com as alexpiet
Git operations for github.com configured to use https protocol
Token: *****
Expected vs actual behavior
I expect gh to supply my credentials when performing git operations. After authorization, it works as expected for a few minutes. Instead after a few minutes git asks for my credentials
I apologize if this issue has been reported before, or if I'm doing something stupid. Any help would be greatly appreciated.
Reacted by Alice, Lucas Gonçalves S., Davide Scandella, Robin Lovelace, Rodrigo Lustosa, shefaee, davus, aplotor, PetteriM1, fergus-ugle and 13 more
In case it matters, when I do re-authorize with gh auth login it prompts me that I'm already logged into github.com. I confirm I do want to re-authenticate. I state my preferred protocol is https. I authenticate Git with github credentials. Then I login with a web browser
Reacted by Manjar, Michael Richardson, MikeyJensenTDLR, Spiros Baxevanakis, Sileo, dns-smitk, aiAdept, Tanner, Lex, MD Iftaker Ahamed Sayem and 4 more
Reacted by Lucas Gonçalves S., jmmayo71, Gaurav, fanesz and Kevin Nacario
If you said "Yes" to that prompt, then I think git authentication should have been set up for you. But from what you're telling, it sounds like that's not the case. Can you share with us the output of:
git config -l | grep credential
Also please check that you don't have an old password for GitHub stored in your ~/.netrc.
Reacted by Nathaniel Bibler, aiAdept and Younsung Lee
Sure, that looks okay, but if you've chosen "yes" to authenticate Git with github credentials, like you've said, then gh should have configured the credential store for you. I was confused why that hasn't happened, that's why I've asked to list git config -l for any credential settings.
Anyway, I'm closing this as duplicate of #2944 and #3796
Reacted by Behzad Shayegh
Reacted by Christian Bouwense, Lucas Saldyt, unsigned, Kevin Nacario, Mahmudur Rahman and Reiko
I had the same issue and on deleting the credentials section in the git config and re-authenticating solved the issue.
git config --global --edit
Reacted by LoicGeekFamily, Aryan Patel, Richard Twena, Abdelaziz W. Farahat, Jeferson Vinícius, Taylor Mulder, Hiki, Markus Mulholland, apmtab, Roger Krolow and 20 more
Reacted by John Clark, Mihir Trivedi and Piotr Flak
Removed the empty ones and still getting the same error,
This is in a repository created using gh repo create with remote added, I just pushed changes to the github and then it stopped working again -- gh auth setup-git does not fix the issue nor does relogging
Reacted by Rodrigo Ipince, Jakub Jareš, Oleksandr Danylchenko, FarisiHannah and An (Jay) Do
I was the same issue, using the gh tool to configure my git worked for me. Here's what I did after I had gh cli installed and authenticated.
gh auth setup-git
Reacted by Minghao Kong, Apoorva Pendse, Zhengxu Chen, Marcos Candia, Anant Singh, eokoshi, fergus-ugle, Matt Johnson, Anton Evzhakov, Jakub Jareš and 87 more
Reacted by Piotr, Shiva T. Kota, Valentin Thorey, Émile, Salun Marvin, Matt Potma, Mohamed, kyle, Berik Visschers, Eric Jain and 86 more
Reacted by Matteo Canu, Abdulrahman Ali, Farhan Kathawala, Ahmed~, Saad Ahmed, Ayush Sharma, Shashwat, Marcos Candia, Gustaw Chojecki (GKC), Anant Singh and 34 more
Reacted by geminigeek, Salun Marvin, aplotor, Matt Potma, Mohamed, Berik Visschers, benjaminS3D, Farhan Kathawala, Yanbo Wong, Ethan Anderson and 33 more
I also have this problem, and I think this issue isn't solved yet, because as @mislav said:
then gh should have configured the credential store for you.
gh is not configuring it properly. From what I understand the only way to fix this is to add it manually to git config.
I think this issue might have to do with the config already being set. I don't know about the others, but I had been doing other things with credential managers and so my credential section of the git config was already set . I think that might cause gh to not configure anything.
When I tried removing the credential section of my .gitconfig and ran gh auth login again it did generate the right config.
It would be nice if someone could fix this.
@ZachHandley, I don't think this has to do with the issue. I might be wrong, but I'm pretty sure gh doesn't configure your git username and email for you. Not being able to commit doesn't have to do with credentials. Credentials are only when you try to communicate with the github server: push (for public repositories) and also fetch and pull (for private repositories). The reason you are getting this error doesn't have to do with credentials, it has to do with that git stores a name and email for every commit.
You need to use git config as described by the error message and the docs. Run these commands, but with you own (user)name and email:
I was the same issue, using the gh tool to configure my git worked for me. Here's what I did after I had gh cli installed and authenticated.
gh auth setup-git
This may have happened to me because i setup my computer with a pre-written script and the times of installation of git and gh may differ
This is the only possible answer I can think of right now
But once i setup again using gh auth setup-git things are normal now
Reacted by Scott Rifkin, Pranav, kaprudy, Mathias Torp, I. Kolbe and desusurya
# first install GIT CLI, not from snap:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 23F3D4EA75716059
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
# Create your token here: created at https://github.com/settings/tokens
# Note: check most boxes that require Read, or you will have to do it again later.
# write it to file ~/mytoken.txt
# now you can configure store where gh will keep credentials:
git config --global credential.helper 'store --file ~/.git-credentials'
/usr/bin/gh auth setup_git
cat ~/.gitconfig
# Hopefully, you can login now:
/usr/bin/gh auth login --with-token < ~/mytoken.txt
# now you can do operations that require authentication (careful!), "git" saves to and reads from store:
git push -f https://github.com/.....
# if it asks for password, give them the token:
Username for 'https://github.com': <your GitHub name>
Password for 'https://[email protected]': <token, not password>
in the place of username : in my case TheNandan
in the place of the password: give the token you generated from profile > setting > developer settings > token
Reacted by Connor, Sébastien Garagnani, woodphrog and Kelvin Mulungu
I was the same issue, using the gh tool to configure my git worked for me. Here's what I did after I had gh cli installed and authenticated. gh auth setup-git
This may have happened to me because i setup my computer with a pre-written script and the times of installation of git and gh may differ This is the only possible answer I can think of right now
But once i setup again using gh auth setup-git things are normal now
By the way, if you guys want to look at the automated scripts I wrote, please refer to github.com/m3rashid/pc_setup
Give it a star if you like :)
Turns out windows wsl ubuntu had both snap gh and apt gh installed, just running snap remove gh and then gh auth login (using a personal access token) did the trick
sudo snap remove git gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? How would you like to authenticate GitHub CLI? [Use arrows to move, type to filter]
Login with a web browser
For me the solution was to manually set git config --global credential.helper store was the solution. Now there is no new prompt to authenticate after restart. It seems the issue remains tho as I had to do this manually, but it is a pretty easy fix at least.
But you have to use the right path to gh (try which gh after installing gh), otherwise you might get an error like the following (which you may not notice if you are doing browser auth, since the browser will pop up immediately over the console and ask you to log in again):
/usr/local/bin/gh auth git-credential get: line 1: /usr/local/bin/gh: No such file or directory
I don't know why gh doesn't offer to fix your .gitconfig file if this entry is missing... it really should offer to do that automatically.
But you have to use the right path to gh (try which gh after installing gh), otherwise you might get an error like the following (which you may not notice if you are doing browser auth, since the browser will pop up immediately over the console and ask you to log in again):
/usr/local/bin/gh auth git-credential get: line 1: /usr/local/bin/gh: No such file or directory
I don't know why gh doesn't offer to fix your .gitconfig file if this entry is missing... it really should offer to do that automatically.
This worked for me. I installed with brew and the path was wrong /opt/homebrew/bin/gh. Thanks!
Activity
alexpiet commentedon Sep 20, 2021
In case it matters, when I do re-authorize with
gh auth loginit prompts me that I'm already logged into github.com. I confirm I do want to re-authenticate. I state my preferred protocol is https. I authenticate Git with github credentials. Then I login with a web browsermislav commentedon Sep 21, 2021
If you said "Yes" to that prompt, then I think git authentication should have been set up for you. But from what you're telling, it sounds like that's not the case. Can you share with us the output of:
Also please check that you don't have an old password for GitHub stored in your
~/.netrc.alexpiet commentedon Sep 21, 2021
After running
And then doing a git pull, things seem to be working as expected.
mislav commentedon Sep 22, 2021
Sure, that looks okay, but if you've chosen "yes" to
authenticate Git with github credentials, like you've said, then gh should have configured the credential store for you. I was confused why that hasn't happened, that's why I've asked to listgit config -lfor any credential settings.Anyway, I'm closing this as duplicate of #2944 and #3796
TheParadox20 commentedon Mar 8, 2022
I had the same issue and on deleting the credentials section in the git config and re-authenticating solved the issue.
git config --global --editdwymark commentedon Jan 5, 2023
I experienced the same problem, but I believe in my it was due to the fact that I used the
ghsnap instead of the apt package (I am on Ubuntu).vilmibm commentedon Jan 7, 2023
Using Snap is wholly unsupported by us and we recommend strongly against it (for reasons like this).
ZachHandley commentedon Jan 18, 2023
I'm experiencing this issue as well, the output of
$git config --global credential.helper storeyieldsRemoved the empty ones and still getting the same error,


This is in a repository created using
gh repo createwith remote added, I just pushed changes to the github and then it stopped working again --gh auth setup-gitdoes not fix the issue nor does reloggingGanasagar commentedon Feb 2, 2023
I was the same issue, using the gh tool to configure my git worked for me. Here's what I did after I had
ghcli installed and authenticated.gh auth setup-gitsumitanilkshirsagar commentedon Apr 6, 2023
I faced the same issue. I had installed gh with snap. I removed it, and installed with sudo apt get, then it started working
prggTheProgrammer commentedon Apr 23, 2023
I also have this problem, and I think this issue isn't solved yet, because as @mislav said:
gh is not configuring it properly. From what I understand the only way to fix this is to add it manually to git config.
I think this issue might have to do with the config already being set. I don't know about the others, but I had been doing other things with credential managers and so my credential section of the git config was already set . I think that might cause gh to not configure anything.
When I tried removing the credential section of my .gitconfig and ran gh auth login again it did generate the right config.
It would be nice if someone could fix this.
prggTheProgrammer commentedon Apr 24, 2023
@ZachHandley, I don't think this has to do with the issue. I might be wrong, but I'm pretty sure gh doesn't configure your git username and email for you. Not being able to commit doesn't have to do with credentials. Credentials are only when you try to communicate with the github server: push (for public repositories) and also fetch and pull (for private repositories). The reason you are getting this error doesn't have to do with credentials, it has to do with that git stores a name and email for every commit.
You need to use git config as described by the error message and the docs. Run these commands, but with you own (user)name and email:
m3rashid commentedon Jun 12, 2023
This may have happened to me because i setup my computer with a pre-written script and the times of installation of git and gh may differ
This is the only possible answer I can think of right now
But once i setup again using
gh auth setup-gitthings are normal nowslgrobotics commentedon Jul 12, 2023
This might help:
Search for more info: https://www.google.com/search?q=git+config+credential.helper
thenandansrinivas commentedon Jan 8, 2024
Hello All,
Even I faced same issue
Solution:
in the place of username : in my case TheNandan
in the place of the password: give the token you generated from profile > setting > developer settings > token
ericshively commentedon Feb 22, 2024
I also encountered this using the snap version of 'gh' on Ubuntu. Uninstalling and using Github official install instructions and re-authing worked.
rsabbarton commentedon May 9, 2024
Same for me. Had to run "snap remove gh" and then use the GH instructions here:
https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt
I had to logout and restart the terminal and then I could run gh auth login. After that the push to the repo worked without issue.
m3rashid commentedon May 9, 2024
By the way, if you guys want to look at the automated scripts I wrote, please refer to github.com/m3rashid/pc_setup
Give it a star if you like :)
shantanuSakpal commentedon Jun 18, 2024
in my case, the error was: /usr/bin/gh auth git-credential get: 1: /usr/bin/gh: not found
solution:
if you have installed gh using snap, remove it
sudo snap remove ghthen install using apt
sudo apt install ghthen login again
gh auth loginthen try pushing again, should work.
xochtil-xerxes commentedon Nov 11, 2024
I ctrl c ctrl v the install steps i got from github itself and this issue occurred. fixed it by just removing and reinstalling it.
Mechazo11 commentedon Jan 18, 2025
Hi @TheParadox20 thank you very much, this worked in my case too.
tuananh131001 commentedon Feb 15, 2025
this is working for me
jtac commentedon Mar 15, 2025
Turns out windows wsl ubuntu had both snap gh and apt gh installed, just running snap remove gh and then gh auth login (using a personal access token) did the trick
sudo snap remove gitgh auth loginAfter this, cloning my private repo worked fine.
GordonRamsay-689 commentedon Mar 21, 2025
For me the solution was to manually set
git config --global credential.helper storewas the solution. Now there is no new prompt to authenticate after restart. It seems the issue remains tho as I had to do this manually, but it is a pretty easy fix at least.lukehutch commentedon Jun 21, 2025
In your
~/.gitconfigyou need:But you have to use the right path to
gh(trywhich ghafter installing gh), otherwise you might get an error like the following (which you may not notice if you are doing browser auth, since the browser will pop up immediately over the console and ask you to log in again):I don't know why
ghdoesn't offer to fix your.gitconfigfile if this entry is missing... it really should offer to do that automatically.Mechazo11 commentedon Nov 12, 2025
This solved my problem today. Ubuntu 20.04 with an Intel iCore 9th gen CPU
joaopgrassi commentedon Jun 10, 2026
This worked for me. I installed with brew and the path was wrong
/opt/homebrew/bin/gh. Thanks!