Lesson 2 — Your First Repository
Learning Objectives
Section titled “Learning Objectives”- Understand what a Git repository is and what the
.gitfolder contains. - Initialise a new repository with
git init. - Stage files with
git addand understand the staging area. - Record a snapshot with
git commitand write a good commit message. - Check repository status with
git statusandgit log. - Create a
.gitignorefile to exclude files Git should not track.
Conceptual Overview
Section titled “Conceptual Overview”What is a repository?
Section titled “What is a repository?”A Git repository (or “repo”) is a folder that Git is tracking. When you run git init inside a folder, Git creates a hidden subfolder called .git. That folder holds the entire history of every file in the project — every version you have ever committed. You should never edit files inside .git directly.
The three areas
Section titled “The three areas”Understanding these three areas is the key to understanding Git:
| Area | What it is |
|---|---|
| Working directory | The files as they exist on your filesystem right now |
| Staging area (index) | A preparation zone — files you have marked as “ready to commit” |
| Repository (history) | The permanent record of all commits |
The workflow is always the same:
- Edit files in your working directory.
- Stage the changes you want to record with
git add. - Commit the staged changes with
git commit.
What makes a good commit message?
Section titled “What makes a good commit message?”A commit message should complete the sentence “If applied, this commit will…”
- Good:
Add quality-control script for FASTQ files - Good:
Fix off-by-one error in read counter - Too vague:
updateorfixorchanges
Short messages (under 72 characters) are fine for most commits.
Worked Examples
Section titled “Worked Examples”1) Create a project folder and initialise a repository
Section titled “1) Create a project folder and initialise a repository”mkdir -p ~/projects/my_analysiscd ~/projects/my_analysisgit initOutput:
Initialized empty Git repository in /home/youruser/projects/my_analysis/.git/git init only needs to be run once per project. The .git folder is now present:
ls -aOutput:
. .. .git2) Create your first file
Section titled “2) Create your first file”nano README.mdType the following inside nano, then press Ctrl+O to save and Ctrl+X to exit:
# My Analysis
This repository contains scripts and notes for my bioinformatics project.Confirm the file exists:
lsOutput:
README.md3) Check the repository status
Section titled “3) Check the repository status”git status tells you what Git sees in your working directory and staging area.
git statusOutput:
On branch main
No commits yet
Untracked files: (use "git add <file>..." to include in what will be committed) README.md
nothing added to commit but untracked files present (use "git add" to track)“Untracked files” means Git can see the file but is not recording changes to it yet.
4) Stage the file
Section titled “4) Stage the file”git add moves a file from the working directory into the staging area.
git add README.mdNo output is expected when this command succeeds. Check the status again:
git statusOutput:
On branch main
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.mdThe file is now in the staging area — it is ready to be committed.
5) Make your first commit
Section titled “5) Make your first commit”git commit -m records the staged changes with the message provided after -m.
git commit -m "Add project README"Output:
[main (root-commit) a3f92c1] Add project README 1 file changed, 3 insertions(+) create mode 100644 README.mdThe hash (a3f92c1) will be different on your machine — it is unique to your commit.
6) View commit history
Section titled “6) View commit history”git log lists all commits from newest to oldest.
git logOutput:
commit a3f92c1d4e5f678901234567890abcdef1234567 (HEAD -> main)Author: Your Name <you@example.com>Date: Thu Jun 26 09:00:00 2025 +0000
Add project READMEgit log --oneline gives a compact one-line-per-commit view. This is useful when the history is long.
git log --onelineOutput:
a3f92c1 (HEAD -> main) Add project README7) Make a second commit
Section titled “7) Make a second commit”Add a new file to practice the full workflow again:
nano notes.mdType the following, then save and exit:
## Session notes
- Installed FastQC- Downloaded SRR1553607 datasetStage and commit:
git add notes.mdgit commit -m "Add session notes"Output:
[main b7c10d2] Add session notes 1 file changed, 4 insertions(+) create mode 100644 notes.mdView the updated history:
git log --onelineOutput:
b7c10d2 (HEAD -> main) Add session notesa3f92c1 Add project README8) Stage multiple files at once
Section titled “8) Stage multiple files at once”Create two more files:
nano sample_list.txtType the following, then save and exit:
SRR1553607SRR1553608SRR1553609nano run_fastqc.shType the following, then save and exit:
#!/usr/bin/env bash# Run FastQC on all FASTQ files in the current directoryfastqc *.fastq -o fastqc_results/Stage both files in one command:
git add sample_list.txt run_fastqc.shCheck status:
git statusOutput:
On branch mainChanges to be committed: (use "git restore --staged <file>..." to unstage) new file: run_fastqc.sh new file: sample_list.txtCommit:
git commit -m "Add sample list and FastQC script"Output:
[main c1e20f3] Add sample list and FastQC script 2 files changed, 5 insertions(+) create mode 100755 run_fastqc.sh create mode 100644 sample_list.txt9) Create a .gitignore file
Section titled “9) Create a .gitignore file”A .gitignore file tells Git which files and folders to ignore completely. This is important for:
- Large data files that do not belong in a repository (
.fastq,.bam,.vcf) - Temporary files created by tools (
*.log,*.tmp) - System files (
.DS_Storeon macOS)
nano .gitignoreType the following, then save and exit:
# Large sequencing data files*.fastq*.fastq.gz*.bam*.bam.bai*.vcf*.vcf.gz
# Tool output directoriesfastqc_results/trimmed/aligned/
# Temporary and system files*.log*.tmp.DS_Store__pycache__/Stage and commit the .gitignore:
git add .gitignoregit commit -m "Add .gitignore for sequencing data and temp files"Output:
[main d2f31a4] Add .gitignore for sequencing data and temp files 1 file changed, 15 insertions(+) create mode 100644 .gitignoreTest it — create a dummy FASTQ file and check whether Git ignores it:
touch test_sample.fastqgit statusOutput:
On branch mainnothing to commit, working tree cleanGit does not list test_sample.fastq because .gitignore excludes *.fastq. Remove the test file:
rm test_sample.fastq10) See what changed in a file
Section titled “10) See what changed in a file”Edit notes.md to add a line:
nano notes.mdAdd a new line at the bottom:
- FastQC completed successfully on all samplesSave and exit. Now run git diff to see what changed before staging:
git diff notes.mdOutput:
diff --git a/notes.md b/notes.mdindex 3b4f2a1..e7c90d2 100644--- a/notes.md+++ b/notes.md@@ -2,3 +2,4 @@
- Installed FastQC - Downloaded SRR1553607 dataset+- FastQC completed successfully on all samplesLines starting with + are additions. Lines starting with - are deletions. Stage and commit the change:
git add notes.mdgit commit -m "Update notes with FastQC results"Exercises
Section titled “Exercises”-
Run
git log --onelinein~/projects/my_analysis. How many commits do you have? -
Create a new file called
environment.mdthat lists the tools you have installed (at least two). Stage and commit it with an appropriate message. -
Edit
README.mdto add a second line describing your project. Rungit diffbefore staging to confirm the change is shown. Then stage and commit. -
Add
*.csvand*.tsvto your.gitignore. Create a dummy file calledmetadata.csvand verify withgit statusthat Git ignores it. Then remove the dummy file. -
Challenge: Run
git log --onelineagain. Your history should now have at least 6 commits. Write down what each commit does in your own words.
Solutions
Section titled “Solutions”Solution 1
Section titled “Solution 1”git log --onelineOutput (yours will show 4 commits from the worked examples):
d2f31a4 (HEAD -> main) Add .gitignore for sequencing data and temp filesc1e20f3 Add sample list and FastQC scriptb7c10d2 Add session notesa3f92c1 Add project READMESolution 2
Section titled “Solution 2”nano environment.mdFile content:
## Software environment
- FastQC 0.12.1- Trimmomatic 0.39- BWA 0.7.17git add environment.mdgit commit -m "Add software environment notes"Solution 3
Section titled “Solution 3”nano README.mdAdd a second line, for example:
Samples: SRR1553607, SRR1553608, SRR1553609git diff README.mdOutput shows the new line with a + prefix.
git add README.mdgit commit -m "Add sample list to README"Solution 4
Section titled “Solution 4”Open .gitignore and add two lines:
nano .gitignoreAdd at the bottom:
*.csv*.tsvSave and exit.
touch metadata.csvgit statusOutput:
On branch mainnothing to commit, working tree cleanmetadata.csv does not appear. Remove it:
rm metadata.csvSolution 5
Section titled “Solution 5”git log --onelineOutput (6 or more commits depending on your exercises):
f4a52b1 (HEAD -> main) Add sample list to READMEe3c41a0 Add software environment notesd2f31a4 Add .gitignore for sequencing data and temp filesc1e20f3 Add sample list and FastQC scriptb7c10d2 Add session notesa3f92c1 Add project README