install.packages("gitcreds")5 GithHub + RStudio
Happy Git and GitHub for the useR is a great resource for connecting Git/GitHub and RStudio.
5.1 Lab Specific Git + RStudio Communication
- Generate token
- Log into https://github.com/
- Go to https://github.com/settings/tokens
- Press
Generate new token - Select
Generate New Token (Fine-grained, repo-scoped)from the dropdown menu - Create token name
- No description
- Select expiration
- Keep public repositories
- Don’t add any permissions
- Click
generate token
Copy token to computer (notes, word, password organizer, etc…)
Enter GitHub Token into R
- Check if the “gitcreds” package is installed
- at the prompt in the Console type ‘gitcreds()’
- if an Error is received, please install package
- at the prompt in the Console type ‘gitcreds()’
- Add your token to R
- in the console at the prompt
>run the command below
- in the console at the prompt
gitcreds::gitcreds_set()Paste token when prompted
To check if this worked run “gitcreds::gitcreds_get()”
also make sure you have packages
rmarkdownandknitrby searching in packages
Create a New Project in RStudio from an existing project on GitHub
Clone Repository
Create a branch in GitHub
For each GitHub repository you will be working on in the lab that is shared among others, you will need to create your own Branch.
Please create your own branch directly in the repository on the GitHub site
Create Pull Request, for review, on GitHub
6 Old Instructions
6.0.1 How to Connect Github and RStudio using a GitHub Access Token
6.0.1.1 Enter your email (used to log into R Studio) and username into RStudio
- Navigate to the Terminal Tab in R Studio
- Type the following in to the Command line
$ git config --global user.email "user@psu.edu"
$ git config --global user.name "First Last"
6.0.1.2 Each person needs to have their own or project branch
First request from the Lab Manager to create your own branch and provide the Name of the Branch (e.g. firstname_lastname).
The lab manager will create this branch on the Github repository site.
6.0.1.3 Enter your branch into the repository in Rstudio
- Navigate to the Terminal Tab in R Studio
- Type the following in to the Command line:
$ git branch -m <branchName>
6.0.1.4 Create an Access Token in Git
Follow the Create a Personal Access Token instructions.
Be sure to copy this token into a safe place. If it is lost, one must be re-created.
6.0.1.5 Clone a Git Repository to RSTudio on TLT Server
- Navigate to the GitHub project page (e.g. https://github.com/gilmore-lab/student-testbed)
- Press the button
Code - Copy the HTTPS link of the project by clicking the little icon to the right of the URL. The link will be something like https://github.com/gilmore-lab/student-testbed.git

- Copy this to another blank page. This will need to be altered to the following: https://oath2:<PersonalAccessToken>@github.com/<repository>/<project>
- The
Personal Access Tokencreated in Git will be used in the above location.https://oath2:<PersonalAccessToken>@github.com/gilmore-lab/student
6.0.1.6 Make changes to branch on repository
- Ensure the branch name is listed in the Git window in R

Always run ‘Git Pull’ before changes are made
Make Changes to File
Commit changes
Run ‘Git Push’ to Your Branch on Github
Go to
github.com/gilmorelab/<repository name>and create a Pull requestNotify the lab manager that a pull request is available on GitHub for
<repository name>
6.0.3 Configure RStudio for git integration
- From within RStudio, open the
Toolsmenu and select theGlobal Options...item. - Select the
Git/SVNpanel in the left column. It is near the bottom of the list. - Check the
Enable version control interface for RStudio projectscheckbox at the top of the window. - Click on the
View public keylink to see if you have a valid SSH RSA Key already. - If the window opens and contains a long text string that begins with “ssh-rsa” and ends with “
(lxclusterapps?)”, where <your_PSU_id>is your PSU ID (e.g.,rog1), you are half-way home. - If the window is opens and is empty, you must generate a new key:
Close the window and click on theCreate RSA Key...button.- From RStudio, select the
Terminalpane. This will bring up a command line with a prompt that looks something like this:bash-4.2$. - Type
ssh-keygen.pyand hit return. This will generate an SSH key. - Type
ls ~/.sshand hit return. You should see something that looks like this:
bash-4.2$ ls ~/.ssh id_rsa id_rsa.pub known_hosts- The
id_rsa.pubis a file containing a ‘public’ key that you can save on GitHub so that GitHub knows who you are when you connect to it from the PSU TLT RStudio server. - (Optional) type
cat ~/.ssh/id_rsa.pubto see the contents of this key file. - Select
Global Options...from the RStudioToolsmenu again. - Select
Git/SVNfrom the left panel. - Select the
View public keylink to view the SSH key you just generated. - Copy the key to the clipboard (command+C on Mac)
- Visit your account on GitHub. Rick’s is at https://github.com/rogilmore.
- Click on your avatar or photo in the upper right hand corner and select the
Settingscommand. - From the list at left, select the
SSH and GPG keyspanel. - Look at the list of SSH keys.
- If there are no SSH keys…
- Press the
New SSH keybutton. - Paste the key you generated in RStudio into the space provided.
- Add a title like
PSU TLTorlxcluster - Press the
Add SSH keybutton to save the key.
- Press the
- If you see an existing key with
PSU TLTorlxclusteryou should already be ready to go. - Return to RStudio, hit
Applyto save your changes, andOkto exit theSettingspanel. - Test the connection between RStudio and GitHub by cloning a repository.
- Visit the lab protocols repository at https://github.com/gilmore-lab/protocols.
- Click on the
Clone or downloadbutton. - Confirm that the window title says
Clone with SSH. If it does not, click on theUse SSHlink on the upper right side. - Click on the clipboard icon to copy the
git@github.com...link to the repository to your clipboard. - Switch back to RStudio.
- Under the
Filemenu, select theNew Projectoption. - Select
Version Control. - Select
Gitin the next window. - Paste the repository link you copies from GitHub into the
Repository URLfield. - Select a name for the local repository. I usually keep the name from GitHub, so in this case, I would use
protocols. - Select a directory/folder where the repository will be copied to. I have an
rstudio/folder I use for this. If you need to create a folder, you may do so. - Click on the
Create Projectbutton. This will copy the repository from GitHub to your personal (PASS) file space on PSU’s servers.