install.packages("gitcreds")
# Store your token securely
gitcreds::gitcreds_set()Setting up Git for RStudio
Overview
This guide explains how to set up Git with RStudio and connect it to GitHub using a Personal Access Token (PAT).
1. Create a GitHub Account
If you don’t have a GitHub account yet, go to https://github.com/join and follow the steps to create one. You will need this account to host repositories and generate a Personal Access Token (PAT).
2. Install Git
Windows
- Download Git: https://git-scm.com/download/win
 - Use default installation options unless you have specific needs.
 
macOS
brew install gitOr install the Xcode Command Line Tools:
xcode-select --installLinux (Debian/Ubuntu)
sudo apt-get update
sudo apt-get install git3. Configure Git
After installation, set your identity in a terminal (or in RStudio’s Terminal tab):
git config --global user.name "Your Name"
git config --global user.email "your@email.com"Check Git is available:
git --version4. Connect Git to RStudio
- Open RStudio → 
Tools→Global Options.
 - Go to Git/SVN.
 - Confirm the path to Git (e.g., 
/usr/bin/gitorC:/Program Files/Git/bin/git.exe).
 - Enable version control interface for RStudio projects.
 
5. Generate a GitHub Personal Access Token (PAT)
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic).
 - Click Generate new token (classic).
 - Select:
- Expiration (e.g., 90 days or “No expiration”)
 - Scopes: check at least
repo(for repository access)
workflow(if you plan to use GitHub Actions)
 
 - Expiration (e.g., 90 days or “No expiration”)
 - Copy and save the token (you will not see it again).
 
6. Store the Token in R
Use the gitcreds R package:
Paste your PAT when prompted. This saves it in your system credential manager.
Check the stored credential:
gitcreds::gitcreds_get()7. Work with Git in RStudio
Clone a repository:
File → New Project → Version Control → Git → paste repo URLConnect an existing project:
Tools → Version Control → Project Setup → Git
Summary
- Install Git on your system.
 - Configure Git with your name and email.
 - Link RStudio to Git.
 - Use a Personal Access Token (PAT) instead of a password.
 - Store the token securely with 
gitcreds. 
Now RStudio is ready to work with GitHub repositories.