Phase 3. Lesson 7 of 7. About 30 minutes.
Plain entry
GitA distributed version control system that tracks changes to files over time, enabling collaboration, branching, and complete history of every modification. Read more → keeps a history of every version of your files. You can see what changed, when, and roll back. Every software team and most infrastructure teams use it. From now on, your course-notes/ folder is a Git repository, and each phase ends with a commit.
Terms
- Repository (repo): a folder Git is tracking. See git.
- Commit: a saved snapshotA saved, point-in-time state of a virtual machine or storage volume that you can roll back to if a change goes wrong. Read more → with a message.
- Staging (
git add): choosing which changes go into the next commit. - Working tree: your files as they are right now.
Depth
One-time setup:
sudo apt install -y git
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
Start the repo:
cd ~/course-notes
git init
git status
Expected output:
Initialized empty Git repository in /home/you/course-notes/.git/
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
phase-1-install/
phase-2-hardware/
Commit:
git add .
git commit -m "initial commit - phases 1-3"
git log --oneline
a1b2c3d (HEAD -> main) initial commit - phases 1-3
The everyday loop: edit, git status, git diff, git add, git commit -m "what and why".
Good commit messages say what changed and why: “phase 4: fstabThe /etc/fstab file that tells Linux which filesystems to mount at boot, where to mount them, and with what options. Read more → recovery notes” beats “update”.
Going further
git log -p shows every change line by line. git restore file throws away uncommitted edits to a file. .gitignore lists files Git should never track; add screenshots over a few MB or anything with passwords. Pushing to GitHub is Phase 10.
Why it works this way
Git records snapshots of your files, so you can see exactly what changed and when. That is why commit messages should say why: the diff already shows what. When something breaks after a change, git log and git diff turn “what did I touch?” into a list you can read.
Self-check
- What is the difference between
git addandgit commit? - Which command shows uncommitted changes?
- Why set
user.email?
Answers: (1) add stages changes; commit saves them as a snapshot. (2) git diff (or git status for a list). (3) Every commit records who made it.
Sources
- Pro Git book, chapters 1 and 2: https://git-scm.com/book/en/v2
- Git reference: https://git-scm.com/docs
- Git source repository: https://github.com/git/git