Step-by-step setup
Set up your first repository, make your first commits, and practice pulling and pushing changes.
1. Today’s class: GitHub and your first repository
Create your GitHub account, install the required software, create your first repository, add your partner as a collaborator, and practice the Git workflow. Write your GitHub username on a sticky note and give it to Jory or Niál by the end of class. They will invite you to the course organization.
2. Practice R in your repository
Create an R script in your repository and work through Intro2R: Basics of R. Commit and push your script as you work.
3. After you join the organization
You are welcome to explore the coding introduction script, but this is optional. We will use our first course template next week for Module 1.
Start where you are. You may skip Steps 1 and 2 if you have already completed them. Complete Steps 3–7 in order. Step 8 is optional.
Create a GitHub account
Already have an account? Sign in at github.com, confirm that you know your username, and skip to Step 2.
- Go to GitHub Sign Up.
- Use an email address you check regularly and choose a professional username. Your username will be visible in repository links and contribution history.
- Verify your email address and sign in.
- Optional: apply for the GitHub Student Developer Pack with your ETH email. Approval is not required to continue this exercise.
Install R, RStudio, Git, and GitHub CLI
Already installed all four? Open RStudio once to confirm it starts, then skip to Step 3.
Install these in this order. R is the language, RStudio is the IDE where you will work (if you prefer to use another IDE, that is fine), Git records and shares changes, and GitHub CLI provides an easier browser sign-in.
- Install R for your operating system.
- Install the free version of RStudio Desktop.
- Install Git. On macOS, opening Terminal and running
git --versionmay prompt you to install the required command-line tools. - Install GitHub CLI.
- Restart RStudio after Git and GitHub CLI are installed, then complete the authentication steps below.
Authenticate with GitHub CLI
In RStudio, open Tools > Terminal > New Terminal and run these commands one at a time:
gh auth login --web --git-protocol https
gh auth setup-git
gh auth status- The first command displays a one-time code and opens GitHub in your browser. Sign in to the correct account, enter the code if asked, and approve access.
- Return to the RStudio Terminal. Run the second command to connect Git to your GitHub CLI login.
- Run the third command. Continue when it says you are logged in to
github.com.
You normally do this only once on each computer. The saved login works with every repository that your GitHub account is allowed to access.
Confirm that RStudio can find Git
In RStudio, open Tools > Global Options > Git/SVN. Confirm that Enable version control interface for RStudio projects is selected and that a Git executable is listed. If it is blank, browse to your Git executable and restart RStudio.
Set the name and email attached to your commits
In RStudio, open Tools > Terminal > New Terminal, then run the following commands with your own details. Use an email connected to your GitHub account.
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Give your GitHub username to the TAs
Jory and Niál need your username before they can invite you to the course GitHub organization.
- Copy your GitHub username from your profile page. Do not send your password.
- Write your GitHub username clearly on a sticky note.
- Give the sticky note to Jory or Niál by the end of class.
- Continue to Step 4 while you wait for the invitation.
- When the invitation arrives, make sure you are signed in to the correct GitHub account, then select Join or Accept invitation.
Create your first repository
- On GitHub, select the + menu at the top right, then select New repository.
- Choose your personal GitHub account as the Owner.
- Name the repository
coding-intro. - Choose Private visibility and select Add a README file.
- Select Create repository.
Confirm that the repository page shows its name and a README.md file before continuing.
Add your partner as a collaborator
Adding your partner lets both of you practice sharing changes through GitHub.
- Open your new repository on GitHub and select the Settings tab.
- In the left sidebar, under Access, select Collaborators or Collaborators and teams.
- Select Add people, search for your partner’s GitHub username, select the matching account, and confirm the invitation.
- If GitHub asks you to choose a role, select Write. Do not give your partner administrator access.
Set up the project in local RStudio
Clone your repository
- On your repository page in GitHub, select the green Code button.
- Select HTTPS, then copy the repository URL. It should end in
.git. - Open RStudio and select File > New Project > Version Control > Git.
- Paste the URL into Repository URL. RStudio should fill in the project directory name automatically.
- For Create project as a subdirectory of, choose a folder where you keep coursework, such as Documents/DSEP. Choose a location you can find again; avoid placing the project inside another Git repository.
- Select Create Project. RStudio will download, or clone, the repository and open the local project.
Check the result
- The project name appears at the top right of RStudio.
- The Files pane shows
README.md. - A Git tab appears next to Environment and History.
Fallback: create a token only if GitHub CLI sign-in does not work
GitHub account passwords do not work for Git operations over HTTPS. If you must use a personal access token:
- Open GitHub’s fine-grained token form.
- Name it
DSEP RStudioand choose an expiration date after the course ends. - For Resource owner, choose the account or course organization where your course repositories will live.
- Under Repository access, choose All repositories if the course will create several repositories under that owner. If that owner also contains unrelated repositories, choose Only select repositories and add each new course repository to this same token.
- Under Repository permissions, give Contents read and write access. Generate the token and copy it immediately; GitHub shows it only once.
- In the RStudio Console, run the commands below. Paste the token only when
gitcredsprompts for it.
install.packages("gitcreds")
gitcreds::gitcreds_set()Keep the token private. Never put it in an R script, README, repository URL, assignment, email, or chat message.
If GitHub marks the token pending or asks you to authorize it for single sign-on, complete that authorization or contact the course team.
Create an R script, commit, pull, and push
This is the workflow you will repeat throughout the course. A commit records a named checkpoint on your computer; a pull downloads commits from GitHub; and a push sends your local commits to GitHub.
Your script should load at least one package and contain a few lines of working code. For example:
library(tidyverse)
library(palmerpenguins)
penguin_summary <- penguins |>
drop_na(species, body_mass_g) |>
group_by(species) |>
summarise(mean_body_mass_g = mean(body_mass_g))
penguin_summary- In RStudio, select File > New File > R Script and save it in the project as
basics-r.R. - If the packages are not installed, run
install.packages(c("tidyverse", "palmerpenguins"))once in the RStudio Console. Do not put the installation command in your script. - Add the package-loading commands and a few lines of code, such as the penguins example above, to your script. Run each line and save the file.
- Continue practicing with Intro2R: Basics of R if you have time.
- Open the Git pane. The new file should appear with a question mark because Git is not tracking it yet.
- Select the checkbox beside
basics-r.R. This adds, or stages, the file for the next commit. - Select Commit. Review the displayed change, enter a short message such as
Practice R basics, then select Commit. - Close the commit window, then select the green upward arrow labeled Push to upload your script to GitHub. Complete GitHub sign-in if prompted.
- Return to the repository page in your browser, refresh it, and confirm that
basics-r.Rappears.
Practice a pull with your partner
- Your partner accepts the collaborator invitation, clones the repository, and opens it in RStudio.
- Your partner adds one comment to
basics-r.R, then commits and pushes the change. - On your computer, select the blue downward arrow labeled Pull in RStudio’s Git pane.
- Open
basics-r.Rand confirm that your partner’s comment appears.
Terminal equivalent
The RStudio buttons run the same Git commands shown below. You do not need to run these now, but you may use them if you prefer the terminal.
git status git add basics-r.R git commit -m "Practice R basics" git pull git push
If the push does not work
- Authentication failed: run
gh auth statusin the RStudio Terminal. If you are not logged in, rungh auth login --web --git-protocol httpsandgh auth setup-gitagain. - 403 or permission denied: confirm that you signed in to the account that joined the course organization and that the organization has authorized your access.
- Repository not found: confirm that you accepted the organization invitation, cloned your own repository, and copied the correct HTTPS URL.
- Push rejected because the remote contains work: select the blue downward arrow to pull, resolve any conflicts, and push again.
gitcreds::gitcreds_delete(), then gitcreds::gitcreds_set() and enter the replacement token.Optional: explore the organization
Not in the organization yet? You are finished for today. Return to this optional step after you accept the invitation.
- Open the course organization and select its Repositories tab.
- Find and open the coding introduction repository.
- Explore the intro script if you wish. You do not need to complete it now.
Finished when...
- You sent your GitHub username to Jory and Niál.
- Your first repository contains a README and your R basics script.
- Your partner has collaborator access to your repository.
- The project opens locally in RStudio and has a Git pane.
- Your commits appear on GitHub and you have practiced pulling a partner’s change.