34

I'm using Git, on Windows, version 2.9.2.windows.1.

I work on a repository project and when I do a push, it asked me to enter my GitHub username and password. I entered both my GitHub username and password to update the project.

In my next push, it doesn't ask for my username and password any more. All my modifications for the project are updated.

It looks like my username and password are "saved". How do I "unsave" them?

How do I sign out?

I tried

git config --global --unset user.name
git config --global --unset user.email
git config --global --unset credential.helper

But they do not make me sign out.

I want to clear my sign in so the next time I make a push, it asks me again to enter my username and password.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Lord Rixuel
  • 1,173
  • 6
  • 24
  • 43
  • 2
    Possible duplicate of [remove credentials from git](http://stackoverflow.com/questions/15381198/remove-credentials-from-git) – dkaz Jul 24 '16 at 07:52
  • @dkaz no answer in the link you provided work. – Lord Rixuel Jul 24 '16 at 14:30
  • No need to edit the question (which is where you present your question, not your solution: I have edited my answer to reflect what you have found) – VonC Jul 24 '16 at 18:53

10 Answers10

33

For Windows 10, if your PC has a different login (a MSFT account) and GitHub is on another login, if you go to control panel → user accounts and search for credential manager, you will see "Web Credentials" and "Windows credentials".

GitHub seems to be taking the default ID that is registered in the PC (Microsoft account). Under Windows Credentials, remove the GitHub login details and try Push again. You will be prompted for a GitHub ID and password explicitly. Once we login that gets stored as a personal access token for Git push.

GitHub credentials

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
27

First, user authentication has nothing to do with user.name and user.email git config.

And second, compared to the old answer "remove credentials from git", the latest Git for Windows uses Git Credential Manager (Git 2.9.2 => GCM 1.5.0).

Check your config (git config -l) and see if "manager" (or, more recently, 2020+: "manager-core") is registered there.
If not, set it up with:

 git config --global credential.helper manager-core

Since its v1.3.0 (April 2016), it had a delete command to purge credentials.

git credential-manager delete <url>

Update 2018: "delete" is now deprecated, use reject:
Update 2020: "reject" is now deprecated, use erase:

git credential-manager erase <url>

Actually, whatever 'xxx' credential manager you are using ('xxx' being the result of git config credential.helper), you can do:

printf "protocol=https\nhost=github.com" | git-credential-xxx erase

# Windows (2020-2021)
printf "protocol=https\nhost=github.com" | git-credential-manager-core erase

# Linux
printf "protocol=https\nhost=github.com" | git-credential-libsecret erase

# MacOs
printf "protocol=https\nhost=github.com" | git-credential-osxkeychain erase

This is better than fiddling with the Credential Manager of your OS.

That git-credential-xxx executable is in usr/libexec/git-core or (for Windows) mingw64/libexec/git-core of your Git installation.
As mentioned here, on MacOS, it should already be in /usr/local/git/bin/.


If git config credential-manager returns store, then Git uses the "store" mode, which saves the credentials to a plain-text file on disk, and they never expire.

type %USERPROFILE%\.git-credentials

I would remove that particular credential helper from the config, as it stores credentials in plain text.


The OP Lord Rixuel actually confirms in the comments it is a native Windows Credential Manager function which provides automatically (Git or not) the credentials:

I see the "Manage your credentials" option, I click on it out of curiosity, then I click on "Windows Credentials", under "Generic Credentials", there is "git:github.com";, I click on it and there is the "Remove" option. I clicked Remove.

When I do a git push, it asks again for my user and my password. Exactly what I want when I want to sign out.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Git Credential Manager was initially introduced with Git for Windows 2.7.3: https://github.com/git-for-windows/git/releases/tag/v2.7.3.windows.1 (March 2016) – VonC Jul 24 '16 at 14:35
  • 1
    just to be sure, the part is the url link for the repository link right? I tried the command but it doesn't seem to work. It said "unknown command clear. please use git-credential-manager ? to display help" – Lord Rixuel Jul 24 '16 at 14:40
  • @LordRixuel what version of git credential manager are you using? And yes, in your case, `` would be https://github.com – VonC Jul 24 '16 at 14:41
  • "Git Credential Manager for Windows version 1.5.0" – Lord Rixuel Jul 24 '16 at 14:43
  • When I retry with delete, it says "Unable to read from stdin" – Lord Rixuel Jul 24 '16 at 14:46
  • @LordRixuel probably because it is not caching that url. What `git config -l` returns? Does it include any credential helper? – VonC Jul 24 '16 at 14:48
  • It has 2 lines of "credential.helper=manager" and 1 line of "credential.helper=store" – Lord Rixuel Jul 24 '16 at 14:50
  • So it does use the Git Credential Manager (unless the line with store appears last, in which case it has precedence) – VonC Jul 24 '16 at 14:52
  • The line with store does appears at last – Lord Rixuel Jul 24 '16 at 14:54
  • OK, then look for a store plain text file under %USERPROFILE%: see https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage – VonC Jul 24 '16 at 14:54
  • In the .git-credentials, there is a https://Personal Access Token:...@github.com/ when i delete the file, i tried a push, the file is recreated. – Lord Rixuel Jul 24 '16 at 15:07
  • @LordRixuel if you simply unregister that credential help, the file will not be recreated. (`git config --edit`) – VonC Jul 24 '16 at 15:10
  • Just to be sure, when I do the --edit command, I just need to delete the line helper = store to unregister it? – Lord Rixuel Jul 24 '16 at 15:14
  • @LordRixuel yes, exactly. – VonC Jul 24 '16 at 15:27
  • I deleted it, .git-credentials doesn't create. When i do a commit and a push, looks like it still have my username and password saved somewhere. (It didn't ask me to enter my user and pass) – Lord Rixuel Jul 24 '16 at 15:37
  • @LordRixuel Maybe it is stored in memory? Try a new CMD Windows (or even a reboot, just for testing) – VonC Jul 24 '16 at 15:58
  • I restart. It still didn't forget my user and password. – Lord Rixuel Jul 24 '16 at 16:05
  • What git remote -v returns? Is it an https url? With password or token embedded in it? Or an ssh url? – VonC Jul 24 '16 at 16:37
  • it's a normal https url link of my github repository – Lord Rixuel Jul 24 '16 at 16:44
  • @LordRixuel Then try again a `git config --edit` or `git config --global --edit` or `git config --system --edit`, and delete any credential.helper line that you can find, in order to make sure no cache is in effect. (no need to restart anything) – VonC Jul 24 '16 at 16:47
  • There no credential.helper line. It still remember my login info. – Lord Rixuel Jul 24 '16 at 16:57
  • Strange: unless the credentials are in the url itself, I don't know how it remembers. Maybe something in the .git folder of the repo? – VonC Jul 24 '16 at 16:58
  • A lot of stuff lol. Folders: hooks, info, logs, objects, refs. Files: .commit.editmsg.swp .config.swl(.swm, .swn, .swo), commit_editmsg, config, description, head, index – Lord Rixuel Jul 24 '16 at 17:02
  • @LordRixuel OK: other test: what would happen if you clone again that repo, make a test commit and push from that new clone? – VonC Jul 24 '16 at 17:07
  • it says the folder already exist and is not an empty directory. do you want I rename the folder, make a git clone and replace the .git ? – Lord Rixuel Jul 24 '16 at 17:10
  • @LordRixuel Sure: please use a local path which does not exist yet: `git clone https://github.com/user/repo C:\path\to\new\repo` with `C:\path\to\new\` already there, but `C:\path\to\new\repo` not created yet. – VonC Jul 24 '16 at 17:12
  • I made a new clone, it didn't ask for my login and password. – Lord Rixuel Jul 24 '16 at 17:21
  • @LordRixuel That is completely expected: it only asks you for authentication when pushing, because only the owner of a repo (or a collaborator) can push to it. But for a public repo, anyone can read/clone/fetch from said public repo. No user/password requested there (for the reading part) – VonC Jul 24 '16 at 17:22
  • my github repository is a public organization link. I'm really afraid of pushing on a computer and then someone manage to push it under my login – Lord Rixuel Jul 24 '16 at 17:26
  • That won't happen: push away. You can create a new branch and push that branch if you want. – VonC Jul 24 '16 at 17:50
  • but anyone could reclone the repository and then pushing if they are on the same computer – Lord Rixuel Jul 24 '16 at 17:52
  • No they won't: your credentials are not, repeat *not* embedded in whatever you are pushing – VonC Jul 24 '16 at 17:52
  • And on the "same computer" part: a/ why would they be on your computer b/ They would be using their profile data, and would not have read access to your user profile C:\Users\yourLogin – VonC Jul 24 '16 at 17:53
  • but what if it's a company computer or school computer? or what if I want to push on a different account? – Lord Rixuel Jul 24 '16 at 17:55
  • Let's test the push first: we'll see first if that pushes and decide after. – VonC Jul 24 '16 at 17:57
  • How did that push go? Reminder "asking for your credentials" only occurs for push operations. Not for clone/fetch. – VonC Jul 24 '16 at 18:14
  • the push works as usual, it just didn't ask for my user and password – Lord Rixuel Jul 24 '16 at 18:17
  • @LordRixuel are you *sure* the git remote -v url does starts with https://github.com/auser/arepo? – VonC Jul 24 '16 at 18:18
  • @LordRixuel And do you see that last pushed commit reflected on the GitHub website? – VonC Jul 24 '16 at 18:18
  • I can see the change on the Github website. For the git remove -v, there are 2 links: origin https://github.com/myorghere/myorghere.github.io.git (fetch) origin https://github.com/myorghere/myorghere.github.io.git (push). Both are https – Lord Rixuel Jul 24 '16 at 18:22
  • @LordRixuel OK: on that same computer, can you ask somebody else to login, clone that same repo in his.her own path, make a commit, and push? – VonC Jul 24 '16 at 18:33
  • omg. somehow, your comment gave me a hint. I know how to get rid of it now. I was gonna create a new user account on my computer but then I see the "Manage your credentials" option, I click on it out of curiousity, then I click on "Windows Credentials", under "Generic Credentials", there is "git:https://github.com", I click on it and there is the "Remove" option. I clicked Remove. When I do a git push, it asks again for my user and my password. Exactly what I want when I want to sign out. – Lord Rixuel Jul 24 '16 at 18:45
  • @LordRixuel Well spotted! I have edited the answer to reference that particular credential Manager. – VonC Jul 24 '16 at 18:52
10

Reason for this Issue :

1.Previously logged in account credentials are saved in Windows Credentials.

2.Due to this, Gitbash gives error and doesn't allow us to login for new credentials

For SOLUTION Follow the steps:

Control Panel -> User Accounts -> Manage your credentials -> Windows Credentials -> under Generic Credentials there are some credentials related to Github, click on them and click "Remove".

This removes any prior logins without any issues. A fresh new login check is provided in Gitbash console which asks for your login credentials in order to save them.

Aniket Patil
  • 771
  • 6
  • 8
9

I found my solution (Thanks to VonC):

Go to: Control PanelUser AccountsManage your credentialsWindows Credentials → under Generic Credentials there are some credentials related to GitHub. Click on them and click "Remove".

It signed me out so the next time I do a push, it asks me to enter my username and my password.

1

If you're using multiple accounts (which is what brought me here), it's more effective to unset the credential manager in the global Git configuration and use the prompt screen.

I was not able to find how to manage multiple accounts, through the credential manager documentation which are rather bare-bones at the moment.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NickersF
  • 341
  • 3
  • 8
1

Also, don't forget to remove your SSH key if you have any. Even if you remove your credentials, if you have an SSH key you will still be able to log on automatically.

1

Because you did login in another account, and that account doesn't have access rights to this repo, if you're using mac os, go to Keychain Access, search for gitlab.com, remove it and try to git clone again.

Hieu Vo
  • 3,105
  • 30
  • 31
1

The only option worked for me to remove storing of Git credentials is the following command. git credential-manager remove

Anuran
  • 11
  • 1
1

The first you should remove token github from Credential Manager steps :

  1. Control Panel -> User Accounts -> Credential Manager
  2. Choose Windows Credentials and remove data of github-authentification.github.auth
Sagar Darekar
  • 982
  • 9
  • 14
-1

If you want to change the account, as as later:

git config --global user.name "new name"
git config --global user.email "new email"
git config --list
git help
git help commit
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131