111

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?

Peter Mortensen
31k22 gold badges111 silver badges134 bronze badges
asked Oct 22, 2017 at 19:48

9 Answers 9

152

Ideally, you should enter:

git config --global credential.helper manager-core
# Since Git 2.39+
git config --global credential.helper manager

This is from the Microsoft multi-platform credential manager GCM.

(After Git 2.38.1, is called manager (no longer "manager-core"))

Then your password (or rather a token is used nowadays) 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 printf "protocol=https\nhost=github.com\nusername=xxx"| git-credential-manager-core erase will remove them (on Windows, Linux or Mac)


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


See also GCM 2.6.1, Jan. 2025, which refers to CVE-2024-50338:

Do not treat the lone carriage-return character (CR, \r) as a line terminator in the credential helper protocol.

answered Oct 23, 2017 at 5:01
Sign up to request clarification or add additional context in comments.

For some reason the command to remove the credentials hung up for me. I found the credentials at Control Panel -> Credential Manager -> Windows Credentials -> Generic Credentials and removed them.
@JACH That will work indeed. As seen in stackoverflow.com/a/39608906/6309, or in command-line: stackoverflow.com/a/48415708/6309
"git: 'credential-manager-core' is not a git command. See 'git --help'."
@Enrico You need a recent Git for Windows (github.com/git-for-windows/git/releases) for credential-manager-core to be recognized. Or you need to install github.com/microsoft/Git-Credential-Manager-Core separately on Linux/Mac.
@AnilS True, I mentioned percent-encoding before.
17

sorry, nothing worked for me (using msys git 2.33.0), here is my solution:

$ git config --global credential.helper store

go to some source directory

$ git add . && git commit -m "some commit" && git push origin master
Username for 'https://github.com': <type user name here>
Password for 'https://<typed user name>@github.com': <type generated token here>
answered Sep 5, 2021 at 0:48

Comments

11

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

answered Feb 11, 2021 at 17:13

I had to do the above, visual studio 2019 wouldn't prompt for credentials after removing them with Windows Credentials Manager.
Credentials should be asked by a pop-up window when you type "git fetch origin" into the Git Bash command tool.
this whole mass, mingw-git didn't work at all.
Set remote url as git remote set-url origin anil.saripiralla%[email protected]/anilsakr/…
4

In windows Git's credential.store plugin which store the credentials in CredentialManager utility is named manager.

In order to set it as credential store for git(if not already set) use below command. This will set the CredentialManager as the git credential store

git config --global credential.store manager

you can verify the same using below(it will give result as manager)

git config credential.helper
answered Aug 19, 2022 at 13:00

These appear to be 2 different settings. Should it be credential.store or credential.helper?
git config --global credential.store will set the credential.store as the global credential store to be used by git. It is already present in windows. git config credential.helper will give you the current settings.
2

I normally prefer to clone my Git repositories using SSH links. Here are my steps for Windows:

  • Generate a public/private key pair through PuTTYgen.
  • Add the public key to my GitHub account.

By doing this, I can easily clone my repositories without needing to use my GitHub account password.

Peter Mortensen
31k22 gold badges111 silver badges134 bronze badges
answered Oct 22, 2017 at 21:10

Okay. do I need to find the SSH URL for my repo if i clone it, or do I just use my public key?
Yes you need both.
2

I had a related problem using Windows 10 Pro and Git-2.23.0-64-bit. After I had to change my Gitlab password, fatal: Authentication failed for did occur when- and wherever I tried to push/ pull/... a rep. For me, the following worked out:

Remove git including the respective folders on C: and Install git anew without(!) enabling the Git Credential Manager option in the configuration steps

Afterwards, when I tried to push my rep., the credential manager asked for my credentials one time. Now everything is ok again.

answered Jun 19, 2020 at 13:49

This one was the solution to me.
1

Prior answers are probably out of date for GitHub but may be ok for other git repositories. You'll get an error like this:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/username/repo.git/'

It's probably easier to use the GitHub application.

If you really want to use command line, first generate a token, instructions here: https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

Then you use the token instead of your password. This is painful because the token is a long string of digits that you can't easily memorise, so you'll be cutting and pasting from a password manager or something less secure.

So I recommend running the GitHub Desktop app which you can get from: https://desktop.github.com/

answered Sep 11, 2021 at 7:00

Comments

-1

I tried many of these approaches and could not get the credentials to be requested. What finally worked was to use Azure Devops webapp to clone the reop to VS Code.

answered Sep 12, 2023 at 0:23

Comments

-2

No answer here currently gives the full process and in a Git runtime-agnostic way. I.e. a solution that will work no matter if you installed the Git Bash package or in an other way (via a more sensible way like with a package manager for instance).

Here is one:

# 1. Install Git Credential Manager (`git-credential-manager-core` has been renamed and is deprecated.), for instance with `scoop`:
scoop install git-credential-manager
# 2. Configure Git to use it
git config --global credential.helper manager
git config --global credential.useHttpPath true

And that's it, you can now authenticate via SSO with your Microsoft Office 365 account to the git remote, without having to enter a generated credential password from your git host every time.

answered Apr 19, 2023 at 15:50

scoop command not found
@MagnoC Just make a freaking google search. How lazy are you ?
What arrogant are you talking about ? Your first comment was the most disrespectful kind of comments there is on this site. Literally taking other people for their own servants, having zero politeness in your formulation. Of course no one is ever gonna help you. Do you think I care about your little downvote ? However you will shortly get banned for using multiple accounts. Bye. Go use chatgpt now.
My first comment was: "scoop command not found". Do you think that little note was the most disrespectful thing you've seen around here? What kind of woke doll are you? Want to talk about politeness? Stop deleting people's comments.
And what multiple accounts are you talking about? I've had just this one account for decades. Whatever you're smoking, quit now. It's damaging your sense of reality.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.