What you'll learn
- Explain commits, history and diffs
- Describe the working directory, staging area and repository
- Explain how branches let work happen safely in parallel
- Tell Git apart from GitHub and know what version control does not do
Understand what version control solves and what commits, history, diffs, repositories and branches are.
Why it matters
Without version control, projects end up with folders like report-final.docx, report-final-v2.docx and report-final-REALLY-final.docx, and nobody knows which one is current or what changed between them. With several people, it gets worse: two people edit the same file and one person's work is lost.
Version control records every saved change to a project, who made it and why, and lets you compare, undo and combine changes safely. Git is by far the most widely used version control system. Software teams, data science teams, infrastructure teams and many researchers and teachers use it every day, and nearly every technical job posting assumes you know it.
The core ideas
Repository
A repositoryA project folder that Git tracks, with its history stored in a hidden .git folder. (repo) is a project folder that Git tracks. Git keeps its records in a hidden .git folder inside it. Delete .git and the folder becomes an ordinary folder again, with no history.
Commit
A commitA saved snapshot of the project with a message, author, date, parent link and unique hash. is a saved snapshot of the whole project at one moment, plus:
- a message describing the change ("Add unit conversion for pressure"),
- the author and date,
- a link to the parent commit before it,
- a unique ID, a hash such as
3f9c2e1, computed from the contents.
Commits are cheap, so you make many small ones. Each should be one logical change.
History
Linked commits form the history. git log --oneline shows it, newest first:
3f9c2e1 Add unit conversion for pressure
a17b4d0 Fix rounding in temperature report
9e02c55 Create README with setup stepsYou can go back to any commit, see who changed a line and why (git blame), and find when a bug appeared.
Diff
A diffA line-by-line view of what changed between two versions; - marks removed lines and + added ones. shows exactly what changed between two versions, line by line:
- rate = 0.08
+ rate = 0.0825Lines starting with - were removed and lines with + were added. Reviewing diffs is how teams check each other's work before it is accepted.
The three areas
Git separates your work into three places:
- Working directory: the files as you are editing them now.
- Staging areaThe set of changes chosen with git add to go into the next commit. (index): the changes you have chosen to include in the next commit, added with
git add. - Repository: the committed history, written with
git commit.
Staging lets you commit some changes and keep others for later, so each commit stays focused.
Branches
A branchA separate line of development: a movable label pointing at a commit. is a separate line of development: a movable label pointing at a commit. You can start a branch to try an idea, commit on it freely, and merge it back into main when it works, or throw it away. Branches make it safe to experiment. You will use them in lesson 3 of this module.
Git versus GitHub
- Git is the tool on your computer. It works completely offline.
- GitHub (and alternatives such as GitLab and Bitbucket) is a website that hosts Git repositories online so people can share them, review changes in pull requests, track issues and run automated checks.
Git is distributedEvery clone of a Git repository has the full history, so you can commit without a network connection.: every clone of a repository has the full history, so there is no single point of failure and you can commit without a network connection.
What version control is not
- It is not a backup by itself. Commits live on your machine until you push them to a remote such as GitHub.
- It is not great for large binary files (videos, big datasets). Text such as code, Markdown, CSV and configuration files works best, because Git can show line-by-line diffs.
- It does not keep secrets safe. Anything committed stays in history even if you delete it later, so passwords and API keys must never be committed.
Worked example: a bug hunt
A colleague reports that the monthly report's totals are wrong since last week. With Git, you run git log to see the commits from that week, open the diff of the one that touched the totals code, and find that a rate was changed from 0.08 to 0.8. You fix it in a new commit with the message "Fix tax rate typo introduced in a17b4d0". Without version control, you would be comparing files by eye.
Quick recap
- A repository is a tracked folder; history is stored in
.git. - A commit is a snapshot plus message, author, date, parent and hash.
- Diffs show line-by-line changes; history lets you compare and undo.
- Working directory, staging area and repository are the three areas.
- Branches let you work safely in parallel; GitHub hosts repos and adds collaboration tools.
Try it
Open the Do tab and take the quiz.
Key terms (6)
- repository
- A project folder that Git tracks, with its history stored in a hidden .git folder.
- commit
- A saved snapshot of the project with a message, author, date, parent link and unique hash.
- diff
- A line-by-line view of what changed between two versions; - marks removed lines and + added ones.
- staging area
- The set of changes chosen with git add to go into the next commit.
- branch
- A separate line of development: a movable label pointing at a commit.
- distributed
- Every clone of a Git repository has the full history, so you can commit without a network connection.