Git Credentials¶
"Git keeps asking for my token" is one of the most common Workbench tickets. HTTPS remotes need a personal access token (PAT), and by default Git does not remember it.1
Options¶
| Approach | Where the PAT lives | Survives session restart | Notes |
|---|---|---|---|
credential.helper cache |
Memory of a helper daemon | No (lost when the session or daemon ends, including a system restart) | Fine for short sessions2 |
credential.helper store |
Plain text in ~/.git-credentials |
Yes | Simple; not encrypted, protected only by filesystem permissions, so the file should be 06001 |
gitcreds / credentials R packages |
Git credential store | Depends on helper | Friendly R interface45 |
| SSH keys | ~/.ssh/ |
Yes | No token expiry prompts; needs SSH egress, normally port 22 (GitHub also allows SSH over port 443 as a firewall workaround)7 |
| Workbench managed credentials | Brokered by Workbench | Yes | For supported integrations only: AWS, Azure, Databricks, Snowflake, and custom OAuth2 providers8 |
Home directories are private to each user (0700), so a 0600 credentials file in a home directory is usually acceptable. Your security team may require otherwise; ask.
Per user setup (recommended)¶
Each user runs once, in a Workbench terminal:
The next git push prompts for username and PAT and saves them. Confirm the file is private:
From R, gitcreds::gitcreds_set() stores the same credential through Git's credential helper4:
usethis::git_sitrep() reports the current Git and GitHub configuration, useful for diagnosing credential problems6:
Server wide default with cache¶
Some sites set a long cache timeout for every user so a PAT is entered once per session. Put it in the system Git config, not in a login script:
28800 seconds is 8 hours. Very long timeouts (a year, 31536000) look convenient but do not help. The cache daemon dies when the session ends, so users are prompted again anyway. A long lived credential in memory is also a larger exposure.2
Avoid git config --global in /etc/profile.d
An older workaround puts git config --global credential.helper ... in /etc/profile.d/rstudio.sh. That rewrites every user's ~/.gitconfig at every login and overrides choices users made themselves. Use git config --system (written once to /etc/gitconfig, and overridden by global and local scope) instead.3
Token expiry¶
PATs expire. When pushes start failing with Authentication failed after months of working, the token expired. The user creates a new PAT and either reruns gitcreds::gitcreds_set() or edits ~/.git-credentials.4
When Git cannot connect at all¶
Timeouts (rather than authentication errors) are network problems. See the worked example in Networking.