Reputation: 549
I'm using RStudio + Github and have been following the instructions here: https://happygitwithr.com/https-pat.html
It works great, except that within a couple of hours the PAT no longer works and I'm prompted to enter a username/password. I go back and generate a new PAT, and repeat. Here's the code I'm using.
> usethis::create_github_token()
• Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
It is also a great idea to store this token in any password-management software that you use
✔ Opening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE TOKEN\'S USE CASE'
> usethis::create_github_token()
• Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
It is also a great idea to store this token in any password-management software that you use
✔ Opening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE TOKEN\'S USE CASE'
> gitcreds::gitcreds_set()
? Enter password or token: <token>
-> Adding new credentials...
-> Removing credetials from cache...
-> Done.
I have also set the following:
git config --global credential.helper 'cache --timeout=10000000'
Upvotes: 4
Views: 756
Reputation: 368181
The PAT can be stored as environment variable so a key=value
assignment in the ~/.Renviron
file is a very possible solution.
Another is to explicitly inject it from ~/.Rprofile
via Sys.setenv(key="value")
.
You can test either in any R session via
> v <- Sys.getenv()
> "GITHUB_PAT" %in% names(v)
[1] TRUE
>
When you create a PAT
(in the GitHub UI) you can give it explicit lifetimes. I happily re-used on this week which I created a year ago for a particular scripting need.
Upvotes: 4