Skip to content

Commit

Permalink
Update "Cache credentials for HTTPS", esp. for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jan 7, 2019
1 parent d6a681b commit 241c968
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions 11_connect-credential-caching.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# Cache credentials for HTTPS {#credential-caching}

If you plan to push/pull using HTTPS, you want Git to cache your credentials (username, password) (or you should set up SSH keys, chapter \@ref(ssh-keys)), so you don't need to enter them over and over again. I suggest you set up one of these methods of authentication on each computer you want to connect to GitHub from.
If you plan to push/pull using HTTPS, you want to cache your credentials (username, password), so you don't need to enter them over and over again. Alternatively, you could set up SSH keys, chapter \@ref(ssh-keys)). I suggest you set up one of these methods of authentication on each computer you want to connect to GitHub from.

I find HTTPS easier to get working quickly. [It is what GitHub recommends](https://stackoverflow.com/a/11041782/2825349), presumably for exactly the same reasons. I started with HTTPS, but eventually switched over to SSH. Either is fine and you can change your mind later.
I find HTTPS easier to get working quickly and **strongly recommend** it when you first start working with Git/GitHub. [It is what GitHub recommends](https://stackoverflow.com/a/11041782/2825349), presumably for exactly the same reasons. I started with HTTPS, but eventually switched over to SSH. Either is fine, and you can change your mind later.

I do not explain all the shell (Appendix \@ref(shell)) and Git commands in detail. This is a black box diagnostic / configuration exercise.
## You might not need to do anything!

As of January 2019, if you install Git using the [methods recommended here in Happy Git](#install-git), it is possible that Git will use a credential helper provided by your operating system. That is, you may not need to do anything special in order to cache your GitHub username and password.

Specifically, if you are on macOS or Windows, don't do anything described here until you have actually proof that it's necessary, i.e. that you have experienced repeated challenges for your username and password when using HTTPS.

### Windows

In my most recent experiments, Git for Windows is configured to store credentials via the Windows Credentials Manager. This meant that I only needed to enter my GitHub username and password once to get setup for HTTPS.

Here’s a command to reveal the configuration and the output I see in a fresh installation of Git for Windows:

``` bash
$ git config --show-origin --get credential.helper
file:C:/Program Files/Git/mingw64/etc/gitconfig manager
```

### macOS

*I'm not currently in a position to say what is true in fresh Git installations.*

## Special consideration re: two-factor authentication

Expand Down Expand Up @@ -54,20 +73,19 @@ and verify your version is 1.7.10 or newer. If not, update Git (chapter \@ref(in

## Turn on the credential helper

#### Windows
#### Windows, plan A

In the shell, enter:
The preferred setting for `credential.helper` is now `manager`, which configures Git to use Git Credential Manager for Windows, which ships with Git for Windows. This may already be configured, but this command sets it explicitly:

git config --global credential.helper wincred
git config --global credential.helper manager

#### Windows, plan B

If that doesn't seem to work, install an external credential helper.
If for some reason, Git Credential Manager does not work, you may have success with an older method, `wincred`:

* Download the [git-credential-winstore.exe](http://gitcredentialstore.codeplex.com/) application.
* Run it! It should work if Git is in your `PATH` environment variable. If not, go to the directory where you downloaded the application and run the following:

git-credential-winstore -i "C:\Program Files (x86)\Git\bin\git.exe"
git config --global credential.helper wincred

This is, however, considered deprecated and suggests you should install the current Git for Windows. So only use this as a temporary solution to get unstuck, until you can upgrade.

#### Mac

Expand Down

0 comments on commit 241c968

Please sign in to comment.