forked from jennybc/happy-git-with-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_connect-credential-caching.Rmd
110 lines (60 loc) · 4.17 KB
/
11_connect-credential-caching.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# 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.
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 swiched 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.
## Get a test repository
You need a functioning test Git repository. One that exists locally and remotely on GitHub, with the local repo tracking the remote.
If you have just verified that you can interact with GitHub (chapter \@ref(push-pull-github)) from your local computer, that test repo will be perfect.
If you have just verified that you can work with GitHub from RStudio (chapter \@ref(rstudio-git-github)), that test repo will also be perfect.
You may proceed when
* You have a test repo.
* You know where it lives on your local computer. Example:
- `/home/jenny/tmp/myrepo`
* You know where it lives on GitHub. Example:
- `https://github.com/jennybc/myrepo`
* You know the GitHub repo is setup as a remote. In a shell (Appendix \@ref(shell)) working directory set to the local Git repo, enter:
git remote -v
Output like this confirms that fetch and push are set to remote URLs that point to your GitHub repo:
origin https://github.com/jennybc/myrepo (fetch)
origin https://github.com/jennybc/myrepo (push)
Now enter:
git branch -vv
Here we confirm that the local `master` branch is tracking your GitHub master branch (`origin/master`). Gibberish? Just check that your output looks similar to mine:
master b8e03e3 [origin/master] line added locally
## Verify that your Git is new enough to have a credential helper
In a shell (Appendix \@ref(shell)), do:
git --version
and verify your version is 1.7.10 or newer. If not, update Git (chapter \@ref(install-git)) or use SSH keys (chapter \@ref(ssh-keys)).
## Turn on the credential helper
#### Windows
In the shell, enter:
git config --global credential.helper wincred
#### Windows, plan B
If that doesn't seem to work, install an external credential helper.
* 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"
#### Mac
Find out if the credential helper is already installed. In the shell, enter:
git credential-osxkeychain
And look for this output:
usage: git credential-osxkeychain <get|store|erase>
If you don't get this output, it means you need a more recent version of Git, either via command line developer tools or Homebrew. Go back to the Mac section of chapter (\@ref(install-git)).
Once you've confirmed you have the credential helper, enter:
git config --global credential.helper osxkeychain
#### Linux
In the shell, enter:
git config --global credential.helper 'cache --timeout=10000000'
to store your password for ten million seconds or around 16 weeks, enough for a semester.
### Trigger a username / password challenge
Change a file in your local repo and commit it. Do that however you wish. Here are shell commands that will work:
echo "adding a line" >> README.md
git add -A
git commit -m "A commit from my local computer"
Now push!
git push -u origin master
One last time you will be asked for your username and password, which hopefully will be cached.
Now push AGAIN.
git push
You should NOT be asked for your username and password, instead you should see `Everything up-to-date`.
Rejoice and close the shell.