Git & GitHub essentials

Module I · Day 1 · 1 hour

Christian González Martel

Department of Quantitative Methods in Economics and Management · ULPGC

Juan M. Hernández Guerra

Department of Quantitative Methods in Economics and Management · ULPGC

April 23, 2026

Why version control?

  • Keep a full history of every change — who, what, when, why.
  • Collaborate without emailing analysis_final_v3_reallyfinal.R.
  • Revert safely when an experiment breaks your code.
  • Make your work reproducible and publicly auditable.

Important

In this course every exercise you submit lives on GitHub. The workflow has to be working for you by the end of this hour.

Git vs GitHub

Git GitHub
What it is A tool that tracks changes A web service that hosts Git projects
Runs Locally, on your laptop On github.com
Needed for Any version control at all Sharing, collaboration, PRs
Cost Free, open source Free for public repos and education

You need both: Git installed locally, a GitHub account online.

The three Git areas

┌─────────────┐   git add   ┌─────────────┐  git commit  ┌────────────────┐
│   Working   │ ──────────▶ │   Staging   │ ───────────▶ │  Local repo    │
│  directory  │             │   (index)   │              │  (your laptop) │
└─────────────┘             └─────────────┘              └────────────────┘
                                                                  │
                                                         git push │
                                                                  ▼
                                                         ┌────────────────┐
                                                         │  GitHub remote │
                                                         └────────────────┘

In this course you drive every arrow from RStudio’s Git pane, not from a terminal.

Setup (one-off)

Step 1 · Install Git

  • macOS · brew install git, or install the Xcode Command Line Tools.
  • Windows · download Git for Windows and accept the defaults.
  • Linux · sudo apt install git (Debian/Ubuntu) or sudo dnf install git (Fedora).

After install, restart RStudio. It detects Git automatically.

Step 2 · Set your identity — no terminal

From the R console:

usethis::use_git_config(
  user.name  = "Your Name",
  user.email = "you@ulpgc.es"
)

Every commit you ever make will be signed with this name and email. Use the same email you will register with on GitHub (next step).

Step 3 · GitHub account + PAT

Create a GitHub account at https://github.com/signup with your ULPGC email. Apply for the free Student Developer Pack — private repos, Copilot and more.

Create a Personal Access Token (PAT) from R:

usethis::create_github_token(
  scopes      = c("repo", "user", "workflow"),
  description = "R on my laptop · TIDES course",
  expiration  = 90                 # 90 days covers the whole course
)

The browser opens on GitHub. Leave the fields as prefilled, confirm 90 days, click Generate token. Copy the token immediately — GitHub never shows it again.

Step 3 · Save the token

Back in R, paste the token into the credential store:

gitcreds::gitcreds_set()

Verify everything works

usethis::git_sitrep()

All rows should show ✅ green. If anything is red, re-run the step the report points to.

Core vocabulary

  • Repository (repo) · a project folder tracked by Git.
  • Commit · a saved snapshot with a message.
  • Branch · an independent line of development.
  • Remote · a copy of the repo hosted elsewhere.
  • Fork · your personal copy of someone else’s repo on GitHub.
  • Pull Request (PR) · a proposal to merge changes, with review.
  • Clone · local download of a remote repo.
  • Push / Pull · send / receive commits to / from a remote.
  • Sync fork · one-click update of your fork from the original repo.

The course workflow

How everything flows

flowchart LR
  A[chrglez/<br/>course repo] -->|fork| B[yourname/<br/>course fork]
  B -->|clone| C[RStudio on<br/>your laptop]
  C -->|commit + push| B
  B -->|Pull Request| A
  A -->|review comments| B
  A -.->|Sync fork<br/>web button| B

flowchart LR
  A[chrglez/<br/>course repo] -->|fork| B[yourname/<br/>course fork]
  B -->|clone| C[RStudio on<br/>your laptop]
  C -->|commit + push| B
  B -->|Pull Request| A
  A -->|review comments| B
  A -.->|Sync fork<br/>web button| B

The dashed arrow is the Sync fork button on GitHub — that’s how you pull course updates into your fork without a terminal.

The same story, in words

  1. Fork the course repo on GitHub — one click, one time only.
  2. Clone your fork from RStudio.
  3. Each day: branch → solve → commit → push.
  4. Open a Pull Request against chrglez:main.
  5. Christian reviews with inline comments. PRs are never merged.
  6. If the course repo changed while you worked, click Sync fork on your fork’s page.

Step 1 · Fork the course repo

Go to https://github.com/chrglez/quantitative-methods-master-tides.

Click Fork (top-right). GitHub asks for a name — leave the default. Keep “Copy the main branch only” ticked.

You land on your own copy: github.com/<your-user>/quantitative-methods-master-tides.

Step 2 · Clone your fork from RStudio

On your fork’s page, click Code → HTTPS and copy the URL.

In RStudio:

  1. File → New Project → Version Control → Git.
  2. Paste the URL into Repository URL.
  3. Choose a stable parent folder (~/Documents or equivalent — not Desktop or OneDrive).
  4. Click Create Project.

RStudio clones, opens the project, and the Git pane appears in the top-right.

Step 3 · Add the upstream remote (safety net)

Note

Main way to sync · the Sync fork button on GitHub. This step adds an upstream reference locally as a backup, in case you ever need to sync from RStudio instead of the web.

Inside RStudio, open Tools → Terminal → New Terminal and paste:

git remote add upstream https://github.com/chrglez/quantitative-methods-master-tides.git
git remote -v

The second line should print two remotes: origin (your fork) and upstream (the course repo). Close the terminal — in the daily flow you sync from the GitHub web button.

For the alternative ways to sync a fork, see GitHub’s docs: https://docs.github.com/es/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork.

⚠️ Never commit on main

The main branch of your fork is a read-only mirror of the course repo. If you accidentally commit to it, syncing with upstream becomes painful.

Every day you work on a new branch, named after the day: day-1, day-2, … day-6.

If in doubt, look at the branch selector at the top-right of the Git pane. It always tells you where you are.

One branch per day

gitGraph
  commit id: "course v0"
  commit id: "sync from upstream"
  branch day-1
  checkout day-1
  commit id: "Day 1 solution"
  checkout main
  commit id: "sync from upstream"
  branch day-2
  checkout day-2
  commit id: "Day 2 solution"
  checkout main
  commit id: "sync from upstream"
  branch day-3
  checkout day-3
  commit id: "Day 3 solution"

  • main is a mirror of the course repo — it only moves forward via Sync fork, never by your commits.
  • Each day-N branch carries one day’s work and becomes one PR.
  • Branches are never merged back — your fork is the audit trail.

Day-to-day workflow

① Sync your fork · in the browser

Go to github.com/<your-user>/quantitative-methods-master-tides.

If Christian updated the course repo while you were away, a banner appears:

This branch is N commits behind chrglez:main · Sync fork ▼

Click it → Update branch. Done, one click.

Then in RStudio’s Git pane click Pull (blue down arrow) to bring those commits to your laptop.

② Start a branch for the day · Git pane

In the Git pane (top-right of RStudio):

  1. Click the branch dropdown → New Branch…
  2. Name it day-1 (or day-N).
  3. Leave Remote: origin and tick Sync branch with remote.
  4. Click Create.

You are now on day-1, main is safe.

③ Solve the exercise

Open exercises/day1/exercise-template.R. Fill in your solutions using what we covered in Data in R. Save (Ctrl + S).

Run the script top-to-bottom (Ctrl + Shift + Enter) to confirm it runs without errors.

④ Commit · Git pane

In the Git pane:

  1. Tick the checkbox next to exercises/day1/exercise-template.R.
  2. Click Commit.
  3. A dialog opens. Write a message: “Day 1 solution”.
  4. Click Commit.

RStudio shows the green confirmation. Your commit exists locally.

⑤ Push · Git pane

Click the green up arrow (Push) in the Git pane.

RStudio sends your branch to GitHub. The first time per branch it sets the upstream tracking automatically (because you ticked Sync branch with remote in step ②).

⑥ Open the Pull Request · in the browser

Go back to your fork on GitHub. A yellow banner appears:

day-1 had recent pushes · [ Compare & pull request ]

Click it. The PR form opens with the right defaults:

  • base · chrglez/quantitative-methods-master-tides, branch main
  • compare · <your-user>/quantitative-methods-master-tides, branch day-1

Title: Day 1 — Your Full Name. Click Create pull request.

That’s the whole loop

You have submitted. Christian receives a notification, reads the PR, leaves inline comments, and eventually closes it.

For the next day, start again from ① Sync your fork.

Commit messages that don’t suck

Bad

asdf
update
fix
final version
ok

Good

Day 1 solution
Add summary table by island
Fix NA handling in occupancy_rate
Rename variable for clarity

Imperative mood, starts with a verb, ≤ 50 chars.

Common pitfalls

  • Never commit secrets.Rdata, tokens, credentials. The .gitignore already excludes most traps.
  • Never commit on main — branches exist for this.
  • First Push — RStudio handles the upstream tracking automatically if you ticked Sync branch with remote when creating the branch.
  • Authentication failed? Your PAT may have expired. Run usethis::create_github_token(expiration = 90) and gitcreds::gitcreds_set() again.
  • Large files (>50 MB) don’t belong in Git. Put them under datasets/raw/ (gitignored) and commit the download script.

Where to ask for help

  • Happy Git with R · Jenny Bryan’s canonical guide.
  • GitHub Skills · short interactive tracks.
  • Inside this repo · exercises/README.md, tutorial hours on the welcome deck.

Your turn

In the next 20 minutes, do all of these:

  1. Fork the course repo and clone it from RStudio.
  2. Add upstream from the Terminal · one time, as a safety net.
  3. Create a day-1 branch.
  4. Write your name at the top of exercises/day1/exercise-template.R.
  5. Commit and Push from the Git pane.
  6. Open the PR on GitHub with the right title.

I’ll come around the room to catch anyone stuck.