Skip to content

git asks for password despite authentication with gh #4351

Closed

Description

@alexpiet

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://[email protected]':
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.

Activity

  1. added
    bug
    on Sep 20, 2021
  2. alexpiet commented on Sep 20, 2021

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

  3. mislav commented on Sep 21, 2021

    @mislav
    Contributor

    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.

  4. added
    more-info-needed
    on Sep 21, 2021
  5. alexpiet commented on Sep 21, 2021

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

  6. mislav commented on Sep 22, 2021

    @mislav
    Contributor

    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

  7. TheParadox20 commented on Mar 8, 2022

    @TheParadox20

    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

  8. dwymark commented on Jan 5, 2023

    @dwymark

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

  9. vilmibm commented on Jan 7, 2023

    @vilmibm
    Contributor

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

  10. ZachHandley commented on Jan 18, 2023

    @ZachHandley

    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

  11. Ganasagar commented on Feb 2, 2023

    @Ganasagar

    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

  12. sumitanilkshirsagar commented on Apr 6, 2023

    @sumitanilkshirsagar

    I faced the same issue. I had installed gh with snap. I removed it, and installed with sudo apt get, then it started working

  13. prggTheProgrammer commented on Apr 23, 2023

    @prggTheProgrammer

    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.

  14. prggTheProgrammer commented on Apr 24, 2023

    @prggTheProgrammer

    @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 [email protected]
    
  15. m3rashid commented on Jun 12, 2023

    @m3rashid

    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

  16. slgrobotics commented on Jul 12, 2023

    @slgrobotics

    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://[email protected]': <token, not password>
    

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

  17. thenandansrinivas commented on Jan 8, 2024

    @thenandansrinivas

    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

  18. ericshively commented on Feb 22, 2024

    @ericshively

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

  19. rsabbarton commented on May 9, 2024

    @rsabbarton

    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.

  20. m3rashid commented on May 9, 2024

    @m3rashid

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

  21. shantanuSakpal commented on Jun 18, 2024

    @shantanuSakpal

    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.

  22. xochtil-xerxes commented on Nov 11, 2024

    @xochtil-xerxes

    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.

  23. Mechazo11 commented on Jan 18, 2025

    @Mechazo11

    git config --global --edit

    Hi @TheParadox20 thank you very much, this worked in my case too.

  24. tuananh131001 commented on Feb 15, 2025

    @tuananh131001

    gh auth setup-git

    this is working for me

  25. jtac commented on Mar 15, 2025

    @jtac

    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

    Paste an authentication token

    After this, cloning my private repo worked fine.

  26. GordonRamsay-689 commented on Mar 21, 2025

    @GordonRamsay-689

    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.

  27. lukehutch commented on Jun 21, 2025

    @lukehutch

    In your ~/.gitconfig you need:

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

    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.

  28. Mechazo11 commented on Nov 12, 2025

    @Mechazo11

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

    This solved my problem today. Ubuntu 20.04 with an Intel iCore 9th gen CPU

  29. joaopgrassi commented on Jun 10, 2026

    @joaopgrassi

    In your ~/.gitconfig you need:

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

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmore-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions