Remove credentials from Git

后端 未结 30 1669
不知归路
不知归路 2020-11-21 10:13

I\'m working with several repositories, but lately I was just working in our internal one and all was great.

Today I had to commit and push code into other one, but

相关标签:
30条回答
  • 2020-11-21 10:43

    To add to @ericbn 's https://stackoverflow.com/a/41111629/579827 here are sample commands I've embedded in a script I run to update all my passwords whenever they are renewed. It's probably not usable as-is as it's quite specific but it shows real life usage of cmdkey.exe.

    ⚠ This is a shell script run in cygwin

    ⚠ This works because I use private git repos that all authenticate with the same password (you probably don't want to loop over with the same credentials, but you may reuse this sample /list command to extract a list of already registered credentials) ⚠

    entries=`cmdkey.exe /list: | grep git | sed -r -e 's/^[^:]+:\s*(.*)$/\1/gm'`
    for entry in ${entries}
    do
        cmdkey.exe "/delete:${entry}"
        cmdkey.exe "/generic:${entry}" "/user:${GIT_USERNAME}" "/pass:${GIT_PASSWORD}"
    done
    
    0 讨论(0)
  • 2020-11-21 10:44

    If your credentials are stored in the credential helper (generally the case), the portable way to remove a password persisted for a specific host is to call git credential reject:

    • in one line:

      $ echo "url=https://appharbor.com" | git credential reject
      
    • or interactively:

      $ git credential reject
      protocol=https
      host=gitlab.com
      username=me@example.com
      ↵
      
      • ↵ is the Enter symbol, just hit Enter key twice at the end of input, don't copy/paste it
      • The username doesn't seem recognized by wincred, so avoid to filter by username on Windows

    After that, to enter your new password, type git fetch.

    https://git-scm.com/docs/git-credential

    0 讨论(0)
  • 2020-11-21 10:46

    For Windows 10, go to below path,

    Control Panel\User Accounts\Credential Manager

    There will be 2 tabs at this location,

    1. Web credentials and 2. Windows credentials.

    Click on Windows credentials tab and here you can see your stored github credentials, under "Generic credentials" heading.

    You can remove those from here and try and re-clone - it will ask for username/password now as we have just removed the stored credential from the Windows 10 systems

    0 讨论(0)
  • 2020-11-21 10:46

    Try this when nothing as mentioned above is working for you.

    git config credential.helper 'cache --timeout=30'
    

    this will remove the cache every 3sec and will ask for username and password.You can re-run the command with increased timeout values.

    0 讨论(0)
  • 2020-11-21 10:47

    Remove this line from your .gitconfig file located in the Windows' currently logged-in user folder:

    [credential]
    helper = !\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\"
    

    This worked for me and now when I push to remote it asks for my password again.

    0 讨论(0)
  • 2020-11-21 10:47

    In my case, I couldn't find the credentials saved in the Windows Credential Manager (Windows 7).

    I was able to reset my credentials by executing

    git config --global credential.helper wincred
    

    It was honestly a hail Mary to see if it would wipe out my credentials and it actually worked.

    0 讨论(0)
提交回复
热议问题