305

Is there a way to save GITHUB's user credentials with TortoiseGit?

It prompts me the below dialog every time whenever I do a push/pull.

I would like to save my user credential information somewhere like how I did with TortoiseSVN.

enter image description here

MrTux
  • 32,350
  • 30
  • 109
  • 146
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
  • 1
    See also: http://stackoverflow.com/questions/8846972/tortoisegit-asking-password – ShloEmi Oct 07 '13 at 06:03
  • You can also use Credential Manager to save/manage credentials. https://stackoverflow.com/a/31782500/730676 – Nikunj Oct 11 '18 at 12:25

10 Answers10

377

For TortoiseGit 1.8.1.2 or later, there is a GUI to switch on/off credential helper.

It supports git-credential-wincred and git-credential-winstore.

TortoiseGit 1.8.16 add support for git-credential-manager (Git Credential Manager, the successor of git-credential-winstore)

For the first time you sync you are asked for user and password, you enter them and they will be saved to Windows credential store. It won't ask for user or password the next time you sync.

To use: Right click → TortoiseGit → Settings → Git → Credential. Select Credential helper: wincred - this repository only / wincred - current Windows user

enter image description here

linquize
  • 19,828
  • 10
  • 59
  • 83
  • 34
    No, you must enable credential helper first. For the first time you sync you are asked for user and password, you enter them and they will be saved to Windows credential store. It won't ask for user or password the next time you sync. – linquize Oct 09 '13 at 01:45
  • 1
    +1, and add one reference, http://code.google.com/p/tortoisegit/issues/detail?id=1762 – Lex Li Oct 27 '13 at 06:48
  • 1
    For reference, see the documentation section [2.35.6.4 Credential](http://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html#tgit-dug-settings-credential). – Scott D. Strader Sep 08 '14 at 18:57
  • 7
    Note: this won't work if your username contains an `@`! At least for me, also this is a reported bug: https://github.com/msysgit/msysgit/issues/258 – OschtärEi Jul 01 '15 at 13:22
  • 1
    Yeah, this isn't working for me against a springloops repo either. there is a @ in my username as well. How annoying. – Jammer Jul 09 '15 at 10:01
  • @Jammer I enabled wincred to save the username. It is working fine. My user name is `user@2` – linquize Jul 19 '15 at 12:21
  • 1
    @Jammer if you embed username in URL, please enter `https://user%402@example.com/repo.git` for username `user@2` – linquize Jul 19 '15 at 12:22
  • 6
    For TortoiseGit 1.8.16 and above, install the Git Credential Manager for Windows - https://github.com/Microsoft/Git-Credential-Manager-for-Windows - and then follow instructions above. GCM also handles the creds for git within Cygwin/babun which is nice. – DrStrangepork Jan 14 '16 at 19:07
  • None of this worked for me, it seems to assume you've already checked out the repo without 2FA enabled as the options aren't available until the repo folder has been cloned. What did work was ensuring when I installed tortoise, to select the git-hub link handler. Then when I cloned a github repo it used their handler which asked for uid, pwd and 2fa code – David Waterworth Jun 14 '18 at 21:37
  • 2
    Note to any having trouble making the wincred option appear: I had to enable admin mode for the settings using the button on the bottom right. It isn't shown in the screenshot. Once I did that, it saved my password. Prior to that it was only saving my username. – Ginger McMurray Dec 29 '19 at 10:18
74

If you're going to downvote this answer

I wrote this a few months prior to the inclusion of git-credential in TortoiseGit. Given the number of large security holes found in the last few years and how much I've learned about network security, I would HIGHLY recommend you use a unique (minimum 2048-bit RSA) SSH key for every server you connect to.

The below syntax is still available, though there are far better tools available today like git-credential that the accepted answer tells you how to use. Do that instead.


Try changing the remote URL to https://username@github.com/username/repo.git where username is your github username and repo is the name of your repository.

If you also want to store your password (not recommended), the URL would look like this: https://username:password@github.com/username/repo.git.

There's also another way to store the password from this github help article: https://help.github.com/articles/set-up-git#password-caching

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • Where i can see the remote url? In Settings -> Remote -> Url is empty. But i given git url when i do clone first time – Murali Murugesan Dec 22 '12 at 05:09
  • 2
    Click on "origin" in the Remote menu to bring up the URL – Robert Rouhani Dec 22 '12 at 05:10
  • I think it is working, but unable to verify as i am getting 'git did not exit cleanly (exit code 128)' – Murali Murugesan Dec 22 '12 at 05:15
  • oops, pulled the URL from an old example. A quick look on one of my repos shows that the URL should actually be: `https://username@github.com/username/repo.git` where both instances of `username` are your username. Updated the answer. – Robert Rouhani Dec 22 '12 at 05:21
  • After trying your solution seems like SSH key has been compromised so GITHub invalidating me. i read this too http://stackoverflow.com/questions/9617336/how-to-resolve-git-did-not-exit-cleanly-exit-code-128-error-on-tortoisegit – Murali Murugesan Dec 22 '12 at 05:21
  • You're not using SSH, you're using HTTPS (though I'd recommend setting up SSH instead of using HTTPS) – Robert Rouhani Dec 22 '12 at 05:22
  • It showing me no support for authentication method available on server after i change my origin URL to git@github.com:myusername/repo.git'' – Murali Murugesan Dec 22 '12 at 05:26
  • I have no other way to go i think. Better i give username and password everytime :( – Murali Murugesan Dec 22 '12 at 05:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/21553/discussion-between-murali-and-robert-rouhani) – Murali Murugesan Dec 22 '12 at 05:28
  • 1
    This solved the problem much faster and in a simpler way: http://stackoverflow.com/questions/8846972/tortoisegit-asking-password – ShloEmi Oct 07 '13 at 06:01
  • -1 sub-optimal solution, exposes password in plain text. The answer probably should be updated. – Mark Rogers May 13 '14 at 20:38
  • I resorted to using this answer because I have mingw64 and I get this log: Skipping command-line '"C:\Program Files\Git\mingw64\bin\..\usr\bin\bash.exe"' ('C:\Program Files\Git\mingw64\bin\..\usr\bin\bash.exe' not found) Need a valid command-line; Edit the string resources accordingly (3x) error: failed to execute prompt script (exit code 1) – C4F Nov 07 '16 at 17:21
25

None of the above answers worked for me using git version 1.8.3.msysgit.0 and TortoiseGit 1.8.4.0.

In my particular situation, I have to connect to the remote git repo over HTTPS, using a full blown e-mail address as username. In this situation, wincred did not appear to work.

Using the email address as a part of the repo URL also did not work, as the software seems to be confused by the double appearance of the '@' character in the URL.

I did manage to overcome the problem using winstore. Here is what I did:

This will copy the git-credential-winstore.exe to a local directory and add two lines to your global .gitconfig. You can verify this by examining your global .gitconfig. This is easiest done via right mouse button on a folder, "TortoiseGit > Settings > Git > Edit global .gitconfig". The file should contain two lines like:

    [credential]
        helper = !'C:\\Users\\yourlogin\\AppData\\Roaming\\GitCredStore\\git-credential-winstore.exe'
  • No other TortoiseGit settings are needed under "Network" or "Credential". In particular: the "Credential helper" pull down menu under "Credential" will have gone blank as a result of these configuration lines, since TortoiseGit does not recognize the new helper. Do not set the pull down menu to another value or the global .gitconfig will be overwritten with an incorrect value! (*)

You are now ready to go:

  • Try to pull from the remote repository. You will notice an authentication popup asking your username and password, the popup should be visually different from the default TortoiseGit popup. This is a good sign and means winstore works. Enter the correct authentication and the pull should succeed.
  • Try the same pull again, and your username and password should no longer be asked.

Done! Enjoy your interactions with the remote repo while winstore takes care of the authentication.

(*) Alternatively, if you don't like the blank selection in the TortoiseGit Credential settings helper pull down menu, you can use the "Advanced" option:

  • Go to "TortoiseGit > Settings > Credential"
  • Select Credential helper "Advanced"
  • Click on the "G" (for global) under Helpers
  • Enter the Helper path as below. Note: a regular Windows path notation (e.g. "C:\Users...") will not work here, you have to replicate the exact line that installing winstore created in the global .gitconf without the "helper =" bit.

    !'C:\\Users\\yourlogin\\AppData\\Roaming\\GitCredStore\\git-credential-winstore.exe'
    
  • Click the "Add New/Save" button

Patrick Atoon
  • 749
  • 7
  • 8
  • 1
    You pointed me in the right direction. Just needed to use "wincred - current Windows user" and enter the username NOT the email address. That solved everything. – Razze Aug 17 '15 at 09:42
  • I'm glad it helped you on the right track! However, the point in my case has to do exactly with the use of an email address. This contains an "@" and will cause problems if you try one of the other recipes. – Patrick Atoon Aug 17 '15 at 20:55
  • 2
    Um, %40 is the code for '@' so if you tried 'https://myEmail%40gmail.com@github.com/username/repo.git' you will be able to put your email address in the .config Still not recommended but, it is possible. – Tom Padilla Oct 19 '15 at 12:25
  • This is the correct, proper way to do this. Download the installer from [Microsoft/Git-Credential-Manager-for-Windows/releases](https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases), then right click the `setup.exe` file, and run as admin. –  Oct 20 '15 at 07:14
22

If you are a windows 10 + TortoiseGit 2.7 user:

  1. for the first time login, simply follow the prompts to enter your credentials and save password.
  2. If you ever need to update your credentials, don't waste your time at the TortoiseGit settings. Instead, windows search>Credential Manager> Windows Credentials > find your git entry > Edit.
Denis Wang
  • 965
  • 12
  • 13
  • 1
    This is the answer you are looking for, if you had changed your Windows password, and Git authentication no longer works... In German Windows, search for "Anmeldeinformationsverwaltung". – Andre Dec 20 '19 at 10:04
  • 1
    omg thankyou. i know we're not supposed to add comments with thankyou. but THANKYOU !! – Stephen Hazel Jan 10 '20 at 18:17
9

For msysgit 1.8.0, download git-credential-wincred.exe from https://github.com/downloads/msysgit/git/git-credential-wincred.zip and put into C:\Program Files\Git\libexec\git-core

For msysgit 1.8.1 and later, the exe is built-in.

in git config, add the following settings.

[credential] helper = wincred

linquize
  • 19,828
  • 10
  • 59
  • 83
8

Saving username and password with TortoiseGit

Saving your login details in TortoiseGit is pretty easy. Saves having to type in your username and password every time you do a pull or push.

  1. Create a file called _netrc with the following contents:

    machine github.com
    login yourlogin
    password yourpassword

  2. Copy the file to C:\Users\ (or another location; this just happens to be where I’ve put it)

  3. Go to command prompt, type setx home C:\Users\

Note: if you’re using something earlier than Windows 7, the setx command may not work for you. Use set instead and add the home environment variable to Windows using via the Advanced Settings under My Computer.

CREDIT TO: http://www.munsplace.com/blog/2012/07/27/saving-username-and-password-with-tortoisegit/

Anthony Keane
  • 519
  • 7
  • 14
  • 2
    That one is the very best solution ! But can you explain the relationship between _netrc file and git ? Can this file store more than one realm ? – Alex Byrth Feb 16 '16 at 23:59
8

[open git settings (TortoiseGit → Settings → Git)][1]

[In GIt: click to edit global .gitconfig][2]

config username and password

thinhnv
  • 81
  • 1
  • 3
1

When updating to Git for Windows 2.35.1.windows.2 from a older major version, you might want to do the following:

  1. Start Git CMD

  2. Run: git credential-manager-core configure

  3. This should give a response like:

    Configuring component 'Git Credential Manager'...

    Configuring component 'Azure Repos provider'...

Now when starting the next Git operation, Git will ask you for selecting an account only once, store it and reuse it for the next operation.

Stefan
  • 11
  • 1
0

Goto the project repo, right click -> 'Git Bash Here'

In the git bash windows type

cd ~
pwd

i get something like this

/c/Users/<windows_username>

Now copy your public and private keys to this path

C:\Users\<windows_username>\.ssh

i got the below files there

id_rsa
id_rsa.pub
known_hosts

here

Now when ever it needs to use the credentials it uses these files and prompt for password if needed.

rajeshk
  • 716
  • 1
  • 11
  • 21
0

I upgraded to my Git for Windows to latest (2.30.0) 64-bit and it works fine now. get the latest from the url https://git-scm.com/download/win and run the commands below to verify. $ git --version $ git version 2.30.0.windows.1

user1419261
  • 829
  • 8
  • 5