Skip to content
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

git asks for password despite authentication with gh #4351

Closed
alexpiet opened this issue Sep 20, 2021 · 19 comments
Closed

git asks for password despite authentication with gh #4351

alexpiet opened this issue Sep 20, 2021 · 19 comments
Labels
bug Something isn't working needs-user-input

Comments

@alexpiet
Copy link

alexpiet commented Sep 20, 2021

Describe the bug

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

Steps to reproduce the behavior

git pull origin master

Username for 'https://github.com':
Password for 'https://alexpiet@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a person access token instead

gh auth status

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.

@alexpiet alexpiet added the bug Something isn't working label Sep 20, 2021
@alexpiet
Copy link
Author

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

@mislav
Copy link
Contributor

mislav commented Sep 21, 2021

I authenticate Git with github credentials.

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.

@alexpiet
Copy link
Author

After running

$git config --global credential.helper store

And then doing a git pull, things seem to be working as expected.

$git config -l | grep credential
credential.helper=store

@mislav
Copy link
Contributor

mislav commented Sep 22, 2021

After running

$git config --global credential.helper store

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

@TheParadox20
Copy link

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

@dwymark
Copy link

dwymark commented Jan 5, 2023

I experienced the same problem, but I believe in my it was due to the fact that I used the gh snap instead of the apt package (I am on Ubuntu).

@vilmibm
Copy link
Contributor

vilmibm commented Jan 7, 2023

Using Snap is wholly unsupported by us and we recommend strongly against it (for reasons like this).

@ZachHandley
Copy link

ZachHandley commented Jan 18, 2023

I'm experiencing this issue as well, the output of $git config --global credential.helper store yields

credential.https://github.com.helper=
credential.https://github.com.helper=!/usr/bin/gh auth git-credential
credential.https://gist.github.com.helper=
credential.https://gist.github.com.helper=!/usr/bin/gh auth git-credential

Removed the empty ones and still getting the same error,
image
image

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

@Ganasagar
Copy link

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

@sumitanilkshirsagar
Copy link

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
Copy link

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.

@prggTheProgrammer
Copy link

@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:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

@m3rashid
Copy link

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

@slgrobotics
Copy link

slgrobotics commented Jul 12, 2023

This might help:

# 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://...@github.com': <token, not password>

Search for more info: https://www.google.com/search?q=git+config+credential.helper

@TheNandan
Copy link

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
Copy link

I also encountered this using the snap version of 'gh' on Ubuntu. Uninstalling and using Github official install instructions and re-authing worked.

@rsabbarton
Copy link

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
Copy link

m3rashid commented May 9, 2024

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 :)

@shantanuSakpal
Copy link

shantanuSakpal commented 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 gh

then install using apt
sudo apt install gh

then login again
gh auth login

then try pushing again, should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-user-input
Projects
None yet
Development

No branches or pull requests