Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lab 1: Git and GitHub

This session introduces version control with Git and GitHub. Setting up these tools first means you can track your work from day one.

Before week 2

Install R and RStudio before next week's lab. Instructions are in Lab 2: Install R and RStudio.


What is version control?

Version control tracks every change you make to your files. Instead of saving report_v2_final_FINAL.docx, you save a single file and Git remembers its entire history. You can go back to any previous version, see exactly what changed, and collaborate without overwriting each other's work.

GitHub is a website that hosts your Git repositories online. It serves as a backup and lets you share your work.

Why bother?

  • Your lab diary and final report will be easier to manage.
  • You will never lose work (every version is saved).
  • Employers value version control skills.
  • It is the standard tool for reproducible research.

Step 1: Create a GitHub account

  1. Go to https://github.com.
  2. Click Sign up and follow the prompts.
  3. Choose a username you are happy to use professionally (e.g., jsmith-nz, not xXx_gamer_xXx).
  4. Verify your email address.

Student benefits

Apply for the GitHub Student Developer Pack with your university email. It includes free private repositories and other tools.

Step 2: Install Git

macOS

Open Terminal (search for it in Spotlight) and type:

git --version

If Git is not installed, macOS will prompt you to install the Xcode Command Line Tools. Follow the prompts.

Windows

Download Git from https://git-scm.com/download/win. Run the installer and accept the defaults.

Verify installation

Open a terminal (Terminal on macOS, Git Bash on Windows) and type:

git --version

You should see something like git version 2.44.0.

Step 3: Configure Git

Tell Git your name and email (use the same email as your GitHub account):

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Step 4: Create your first repository

  1. Go to https://github.com and click the + button (top right), then New repository.
  2. Name it psych-434-lab (or similar).
  3. Add a description (e.g., "Lab diary for PSYCH 434").
  4. Select Private.
  5. Tick Add a README file.
  6. Click Create repository.

Step 5: Clone the repository to your computer

Cloning downloads a copy of the repository to your machine and links it to GitHub.

  1. On your repository page, click the green Code button.
  2. Copy the HTTPS URL.
  3. Open a terminal and navigate to where you want to store your work:
cd ~/Documents
  1. Clone the repository:
git clone https://github.com/YOUR-USERNAME/psych-434-lab.git
  1. Move into the repository folder:
cd psych-434-lab

You now have a local copy linked to GitHub.

Step 6: The basic Git workflow

The everyday workflow has three steps: stage, commit, push.

1. Make a change

Open the README.md file in any text editor and add a line, such as:

This is my lab diary for PSYCH 434 (2026).

Save the file.

2. Stage the change

Staging tells Git which changes you want to include in your next snapshot:

git add README.md

To stage everything at once, use git add -A.

3. Commit the change

A commit is a snapshot with a short message describing what you did:

git commit -m "update readme with course details"

4. Push to GitHub

Push sends your commits to GitHub so they are backed up online:

git push

Authentication

The first time you push, GitHub will ask you to authenticate. Follow the prompts to sign in through your browser.

Step 7: Check your work

Go to your repository page on GitHub. You should see the updated README file with your changes.

Quick reference

CommandWhat it does
git statusShow which files have changed
git add <file>Stage a file for the next commit
git add -AStage all changes
git commit -m "message"Save a snapshot with a message
git pushUpload commits to GitHub
git pullDownload changes from GitHub
git log --onelineShow commit history

Workflow summary

Edit files → git addgit commit -m "message"git push. Repeat.

Terminal basics

You have already used a few terminal commands (cd, git clone). The terminal is a text interface for your computer. Every command you type runs a small program. Here are the commands you will use most often.

Where am I?

pwd

pwd (print working directory) shows the folder you are currently in.

List files

ls

ls lists the files and folders in the current directory. To see hidden files (names starting with .), use:

ls -a

Git stores its data in a hidden folder called .git. Try ls -a inside your repository to see it.

Change directory

cd ~/Documents/psych-434-lab

cd moves you into a folder. A few shortcuts:

ShortcutMeaning
~Your home folder
..One level up
.The current folder

So cd .. moves up one level, and cd ~ takes you home.

Create a folder

mkdir diaries

mkdir (make directory) creates a new folder.

Create an empty file

touch lab-01.md

touch creates an empty file if it does not already exist.

Terminal quick reference

CommandWhat it does
pwdPrint the current directory
lsList files
ls -aList files including hidden ones
cd <folder>Change directory
cd ..Go up one level
mkdir <name>Create a folder
touch <name>Create an empty file

Organise your repository

Set up a simple folder structure for the course. From inside your psych-434-lab folder:

mkdir diaries

Your repository should look like this:

psych-434-lab/
├── README.md
└── diaries/

Lab diary files go in the diaries/ folder, named by week number:

diaries/
├── lab-01.md
├── lab-02.md
├── lab-03.md
├── ...
└── lab-10.md

There is no lab-07.md (week 7 is test 1). Create your first diary file now:

touch diaries/lab-01.md

Markdown basics

Markdown is a plain-text format that converts to formatted documents. You write in a .md file using simple symbols for headings, bold, lists, and so on. GitHub renders markdown automatically, so your diary will look formatted when you view it online.

Headings

Use # symbols. More # signs mean smaller headings:

# Heading 1
## Heading 2
### Heading 3

Paragraphs

Separate paragraphs with a blank line. A single line break without a blank line will not start a new paragraph.

Bold and italics

This is **bold** and this is *italic*.

Lists

Unordered lists use -:

- first item
- second item
- third item

Numbered lists use 1., 2., etc.:

1. first step
2. second step
3. third step

Inline code

Wrap code in single backticks:

Use the `git push` command to upload your work.
[GitHub](https://github.com)

Markdown reference

GitHub has a concise guide to GitHub-flavoured markdown: Basic writing and formatting syntax.

Write your first lab diary

Create your week 1 diary entry now. Open diaries/lab-01.md in any text editor and write ~150 words covering:

  1. What this lab covered and what you did.
  2. A connection to the week's lecture content.
  3. One thing you found useful, surprising, or challenging.

Use at least one heading, one bold or italic word, and one list. When you are done, stage, commit, and push:

git add diaries/lab-01.md
git commit -m "add lab 01 diary"
git push

Check your repository on GitHub to confirm the file appears and the markdown renders correctly.

Editors

RStudio is your primary editor for this course. For general-purpose code editing (markdown files, scripts, configuration), VS Code and Zed are good options.

Alternative: GitHub Desktop

If you prefer a graphical interface, download GitHub Desktop. It provides the same stage/commit/push workflow with buttons instead of terminal commands. Either approach is fine for this course.