Skip to content
Ben Tupper edited this page Jan 6, 2026 · 2 revisions

repositories with git

git is a software system to help us build, manage and share a repository of documents. git applications run as command-line tools on macos, Windows and linux, but there are many graphical user interfaces (GUIs) to make using the tools easier. Collections of documents are organized into repositories, and git is used to manage those documents for you.

github is a vendor of cloud-based services to host your git repositories. There are competitors to github including bitbucket and gitlab. We’ll use github for this course.

This document is a barebones manual for creating a github account, installing git (if you don’t have it already), and then connecting your computer and your RStudio installation to github.

Using cloud based repositories like git

repos repos

github

If you already have an account with github you can skip to the git section.

Follow the registration menu at github. Keep in mind that this is a public venue that you may use for years to come; be sure to choose an appropriate username, photo and other information with that in mind.

Like any password, keep these credentials in a secure place (like a password manager).

git

git software must be installed on your machine. Open a terminal on you computer.

Check for git

Type the following in the terminal.

git --version

If you get a meaningful response then skip to either Connect to GitHub with SSH or Connect to GitHub with Personal Access Token. If not then you need to install git. A meaningful response might look like this…

git version 2.39.5 (Apple Git-154)

Install git (if you don’t have it)

Select the appropriate link for accessing the software to download and install git.

macos

windows

linux/unix

Set global git identity

Once you have it installed, set your global identity… name and email will suffice. These can be changed later. Of course, please use the name and email associated with your github account.

git config --global user.name "Jane Doe"
git config --global user.email janedoe@example.com

Connect to GitHub with SSH

The easiest way to connect your account with the GitHub server is to use ssh key exchange.

1. Generate a key on the course server

Use the email address you used to create your GitHub account. You’ll be asked a number of questions to each of which please accept the default by pressing return/enter. Enter this at a Terminal.

ssh-keygen -t ed25519 -C "your_email@example.com"

This will generate two files in a hidden directory within your home directory. One file is intended to be hidden, and the other is to share with other accounts, like github.

2. Copy the public portion of the key

Below we print the contents of the public part of the key.

more .ssh/id_ed25519.pub

Select the entire line that is output and copy it.

3. Open up the settings of your GitHub account

Use your browser to navigate to your github account, and open the settings menu. Then open the SSH and GPG keys menu option in the left hand column. Select the big green New SSH key button. Provide a meaningful name for the key (like “ColbyForecasting”), and paste your copied key into the space provided.

Connect to GitHub with Personal Access Token

At this point you have github account, and you have installed and configured git. Here we set up a Personal Access Token (PAT) This is like passing credentials, so that git can move documents securely between the cloud and your computer.

Invoke R (or RStudio) and then do the following…

1. Install usethis package

In R…

install.packages("usethis")

2. Generate github token

In R type…

usethis::create_github_token()

This should bring you to a webpage with some options for generating the token.

You will need to provide a reasonable purpose for the token plus a duration - 60 days should be fine. Accept the defaults on which elements of the github offereings to permit.

Tokens are similar to passwords, so please store the token securely. If you have a password manager then use that. If you use a little notebook then use that.

3. Store the github token

Finally, we provide RStudio with a copy of that token.

In R type the command below and follow the menu that appears in the console.

gitcreds::gitcreds_set()

In theory that is it! It shouldn’t matter is you used SSH or PAT, you should be able clone, push and pull between your account and GitHub.

Clone this wiki locally