What Is Version Control?
Version control records changes to your files over time so you can review history and go back to any earlier version.
Version control is a system that records changes to a set of files over time. It lets you see who changed what, when, and why, and lets you return to any earlier state.
Why use it?
- Keep a complete history of every change.
- Work on features in parallel without overwriting each other.
- Recover a working version when something breaks.
- Collaborate with a team on the same project.
Git vs GitHub
Git is the version control tool that runs on your computer. GitHub is a website that hosts your Git repositories online so you can share them and work with others. This tutorial covers both.
Example
# Check that Git is installed and see its version
git --versionWhen to use it
- A developer reverts a buggy release to the previous stable commit without losing days of other teammates' work.
- A team of five engineers edits the same Python module concurrently; version control merges their changes without overwriting anyone's work.
- A designer rolls back a CSS file to the version from two weeks ago after a redesign is rejected by the client.
More examples
Show full repository history
Lists every snapshot ever saved, proving you can always see what changed and when.
git log --oneline
# a3f1c2e Add login page
# 9b0d14a Fix typo in README
# 3c8e22f Initial commitRestore a deleted file from history
Demonstrates version control's core promise: nothing is ever truly lost once committed.
# Find the last commit that contained the file
git log -- src/auth.js
# Restore it from that commit
git checkout a3f1c2e -- src/auth.jsCompare two versions of a file
Shows how version control makes it trivial to see exactly what changed between any two points in time.
# Diff between two commits for one file
git diff 9b0d14a a3f1c2e -- src/auth.js
# Diff working copy against latest commit
git diff HEAD -- src/auth.js
Discussion