-
-
Save z3tt/3dab3535007acf108391649766409421 to your computer and use it in GitHub Desktop.
#### 1. Sign up at GitHub.com ################################################ | |
## If you do not have a GitHub account, sign up here: | |
## https://github.com/join | |
# ---------------------------------------------------------------------------- | |
#### 2. Install git ########################################################## | |
## If you do not have git installed, please do so: | |
## Windows -> https://git-scm.com/download/win | |
## Mac -> https://git-scm.com/download/mac | |
## Linux -> https://git-scm.com/download/linux | |
## or: $ sudo dnf install git-all | |
# ---------------------------------------------------------------------------- | |
### 3. Configure git with Rstudio ############################################ | |
## set your user name and email: | |
usethis::use_git_config(user.name = "YourName", user.email = "[email protected]") | |
## create a personal access token for authentication: | |
usethis::create_github_token() | |
## in case usethis version < 2.0.0: usethis::browse_github_token() (or even better: update usethis!) | |
## Note for Linux users: | |
## credentials::set_github_pat() (in line 34) might store your PAT in a memory cache that | |
## expires after 15 minutes or when the computer is rebooted. You thus may wish to do | |
## extend the cache timeout to match the PAT validity period: | |
usethis::use_git_config(helper="cache --timeout=2600000") #> cache timeout ~30 days | |
## set personal access token: | |
credentials::set_github_pat("YourPAT") | |
## or store it manually in '.Renviron': | |
usethis::edit_r_environ() | |
## store your personal access token in the file that opens in your editor with: | |
## GITHUB_PAT=xxxyyyzzz | |
## and make sure '.Renviron' ends with a newline | |
# ---------------------------------------------------------------------------- | |
#### 4. Restart R! ########################################################### | |
# ---------------------------------------------------------------------------- | |
#### 5. Verify settings ###################################################### | |
usethis::git_sitrep() | |
## Your username and email should be stated correctly in the output. | |
## Also, the report shoud cotain something like: | |
## 'Personal access token: '<found in env var>'' | |
## If you are still having troubles, read the output carefully. | |
## It might be that the PAT is still not updated in your `.Renviron` file. | |
## Call `usethis::edit_r_environ()` to update that file manually. | |
# ---------------------------------------------------------------------------- | |
## THAT'S IT! |
This is great. Thank you! One minor suggestion. I wasn't familiar with the usethis::edit_r_environ() and kept trying to figure out how to enter the PAT in the parentheses. A comment like this might help people as clueless as me: #Run this line as is to start the editor
This was godsent
Thank you!
Thanks for the feedback @tomhanna-uh, I adjusted the comments on the usethis::edit_r_environ()
bit, hope it is easier to understand now.
Awesome!
Thank you. This is an easy instruction!
You saved me having to write a poorer version for students this term. Can't thank you enough, Cedric!
Glad so many still find it helpful. And all the best with your course Robert!
Thanks a lot! Very happy to have found your advice on this, after 2 days trial-and-error... Yes, still very helpful for me as newbie :)
Very helpful, thanks!!
Glad I found this relatively early. These kinds of setups take hours sometimes. Thank you!
Under default settings on Linux, credentials::set_github_pat
might store your PAT in a memory cache that expires after 15 minutes (or when the computer is rebooted), potentially leading to a great deal of frustration shortly later.
Linux users may wish to do either extend the cache timeout to match the PAT validity period
usethis::use_git_config(helper="cache --timeout=2600000") #cache timeout ~30 days
or configure one of the alternative methods that stores the PAT to disk (store
or libsecret
based solutions).
Thank you @grady , I#ve added a note to the gist!
@z3tt To be effective, the config change to the cache settings needs to occur before setting the PAT. (currently line 28)
Thanks @grady, I have updated the snippet aaccordingly.
many many thanks for your help, all works fine