Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Git credentials on Windows

Tags:

git

bash

github

I am on a Windows 10 system and am trying to add my credentials to Git in Git Bash. I cannot find a way to store my password.

I checked GitHub's documentation, which said just to enter the line git config --global credential.helper wincred, but that didn't seem to make sense, as there's not prompt to enter a password. I checked Git's documentation, which said to use command git credential-store --file ~/git.store store and fill in all prompts. The bash emulator wasn't able to read the credentials.

Finally, I tried to add my password like I added my email, via git config --global user.password "5ecre7" but after running a sample git clone on a repository I made it responded that I didn't have the access rights. Is there a way to fix this?

like image 896
PJ Tikalsky Avatar asked Oct 22 '17 19:10

PJ Tikalsky


People also ask

How do I add multiple Git credentials in Windows?

Simple 3 step solution: remove your current GitHub credentials from Windows Credential Manager. tell Windows to store different accounts for each of your GitHub repos. provide your username, password once again for each repo when you are prompted for your credentials - this is the last time you need to do that.

Where are git credentials Windows?

It is located at %UserProfile%\. git-credentials , which corresponds to C:\Users\<username>\. git-credentials (unless you've modified the registry to move your user's profile directory elsewhere).

What is git credential Manager for Windows?

Git Credential Manager simplifies authentication with your Azure Repos Git repositories. Credential managers let you use the same credentials that you use for the Azure DevOps Services web portal. Credential managers support multi-factor authentication through Microsoft account or Azure Active Directory (Azure AD).


2 Answers

Ideally, you should enter:

git config --global credential.helper manager-core 

Then your password would be stored in the Windows Credential Manager.
See more at "Unable to change git account".

On the first push, a popup will appear asking for your credentials (username/password) for the target server (for instance github.com)

If not, that might means your credentials were already stored.
If they are incorrect, a simple git credential-manager reject https://github.com will remove them (on Windows, again. On Mac: git credential-osxkeychain erase https://github.com)


With Git 2.29 (Q4 2020), the parser in the receiving end of the credential protocol is loosen to allow credential helper to terminate lines with CRLF line ending, as well as LF line ending.

See commit 356c473 (03 Oct 2020) by Nikita Leonov (nyckyta).
(Merged by Junio C Hamano -- gitster -- in commit 542b3c2, 05 Oct 2020)

credential: treat CR/LF as line endings in the credential protocol

Signed-off-by: Nikita Leonov
Signed-off-by: Johannes Schindelin

This fix makes using Git credentials more friendly to Windows users: it allows a credential helper to communicate using CR/LF line endings ("DOS line endings" commonly found on Windows) instead of LF-only line endings ("Unix line endings").

Note that this changes the behavior a bit: if a credential helper produces, say, a password with a trailing Carriage Return character, that will now be culled even when the rest of the lines end only in Line Feed characters, indicating that the Carriage Return was not meant to be part of the line ending.

In practice, it seems very unlikely that something like this happens. Passwords usually need to consist of non-control characters, URLs need to have special characters URL-encoded, and user names, well, are names.

However, it does help on Windows, where CR/LF line endings are common: as unrecognized commands are simply ignored by the credential machinery, even a command like quit\r (which is clearly intended to abort) would simply be ignored (silently) by Git.

So let's change the credential machinery to accept both CR/LF and LF line endings.

While we do this for the credential helper protocol, we do not adjust git credential-cache--daemon(man) (which won't work on Windows, anyway, because it requires Unix sockets) nor git credential-store(man) (which writes the file ~/.git-credentials which we consider an implementation detail that should be opaque to the user, read: we do expect users not to edit this file manually).

like image 94
VonC Avatar answered Oct 21 '22 17:10

VonC


I tried many things but the Windows Credentials did not added credential for Git. Then I did the following simple action and it resolved my issue.

  • I removed the related credentials from the Windows Credentials Manager.
  • Then I opened the Git Bash from the project folder.
  • Then wrote "git fetch origin" command.
  • Git Bash first asked for the username and then for the password.

Then I checked the Windows Credentials Manager... Voilaaaa ! It now shows a credential like "git:http://username@address"

I tried to add somethings like "[credential] helper = manager/wincred" things in the config file but after this solution no need for that part, I deleted that [credential] section. Some says that this may be because of your git server is not using https. If it is using https may be you can find different solutions. I still have a goofy like smile on my face

like image 41
Gultekin Avatar answered Oct 21 '22 18:10

Gultekin