Remote version control with GitHub

Git vs GitHub

NoteGit lives on your computer. GitHub is a website that talks to Git. They work together — but they are not the same thing.

Git

  • Runs on your machine
  • Tracks changes to files
  • Works entirely offline
  • The version control engine

GitHub

  • A website (cloud hosting)
  • Stores a copy of your repo online
  • Enables sharing, collaboration, and backup
  • The version control destination
ImportantYou can use Git without GitHub — but you can’t use GitHub without Git.

Once you have a local repo, you need to push it to GitHub:

  1. Create a new empty repository on GitHub (no README, no .gitignore)

  2. Connect your local repo to GitHub:

git remote add origin https://github.com/username/repo-name.git
git branch -M main
git push -u origin main
NoteYou only run git remote add once. After that, git push and git pull know where to go.

Alternatively, you can use the GUI in VSCode or RStudio to publish your local repo to GitHub.

  1. Open the Source Control tab (Ctrl+Shift+G)
  2. Click Publish Branch (appears after your first commit)
  3. Sign in to GitHub if prompted
  4. Choose Public or Private
  5. VSCode creates the repo on GitHub and pushes automatically
  6. Future commits: click Sync Changes (↑↓) to push
  1. In the console, run usethis::use_github()
  2. Choose Public or Private when prompted
  3. RStudio creates the repo on GitHub and pushes automatically
  4. Future commits: click the Push button (↑) in the Git tab

In Practice

CautionExercises

2.5 Publish your local spacewalk_analysis repository to GitHub

2.6 Visualise the repository on GitHub — explore the commit history, README, and file structure

2.7 Update one of the files in the repository on your local machine, then push the change to GitHub

Creating repositories

We can also create repositories directly on GitHub in two ways:

Create from scratch

  1. Click New repository on GitHub
  2. Enter a repository name and visibility
  3. Optionally add a README, .gitignore, and license
  4. Click Create repository

Create from a template

  1. Open a template repository
  2. Click Use this template
  3. Choose owner, name, and visibility
  4. Click Create repository from template
NoteIf you already have a local Git project, create an empty GitHub repository (no README or .gitignore) to avoid conflicts on first push.

Cloning

To use a repository created on GitHub, you need to clone it to your local machine.

Cloning is the opposite of publishing: instead of sending your work from your machine to GitHub, you copy a repository from GitHub onto your local machine.

You might clone a repository:

  • When starting a new project from an existing template
  • To get a copy of someone else’s code
  • To work or collaborate on a different machine

From the terminal, clone a repository with:

git clone https://github.com/username/repo-name.git
cd repo-name
Notegit clone downloads the files, full commit history, and Git setup.
  1. Open the Command Palette (Ctrl+Shift+P)
  2. Run Git: Clone
  3. Paste the GitHub repository URL
  4. Choose where to save it on your machine
  5. Click Open when VSCode asks whether to open the cloned repository
  1. Go to File → New Project
  2. Choose Version Control then Git
  3. Paste the GitHub repository URL
  4. Choose where to save the project locally
  5. Click Create Project to open the cloned repository in RStudio
  1. Open the repository page on GitHub
  2. Click the green Code button
  3. Click Open with GitHub Desktop
  4. Choose where to save the repository locally
  5. Click Clone to download and open the repository
TipIf the repository is private, you will need to sign in to GitHub before you can clone it.

In Practice

CautionExercises

2.8 Create a new repository on GitHub named your-username

2.9 Clone the repository to your computer, then open in your preferred IDE

Your GitHub homepage

GitHub has a special trick: a repository named exactly the same as your username becomes your public profile page.

This is a neat, low-effort way to:

  • Introduce yourself and your research
  • Showcase projects and skills
  • Link to publications, datasets, or your lab website
TipDon’t worry about complexity — start with a few lines and links!

In Practice

CautionExercises

2.10 Browse awesome-readme for inspiration

2.11 Write your README.md — don’t forget to commit along the way!

2.12 Once complete, push your changes back to GitHub