What git actually is

Understand what git stores, and know which of the three places your work is in right now.

01of 16
≈ 10Min read
5Parts

Not a folder of copies

Most people picture version control as a stack of backups. Git is closer to a small database: every time you commit, it stores a snapshot of the whole project, gives it an id, and remembers which snapshot came before.

Because a snapshot has an id, and the id is computed from the content, two identical files are stored once, and a commit cannot be altered without its id changing. That is the entire security model and most of the speed.

a commit id is not a serial number
$ git log --oneline
832dbe3 (HEAD -> main) add the fitting notes
23fd5c3 first draft of the price list

Three places, and every command moves between them

Almost every confusion in git is a question about which of these three a command touches. git add copies from the working tree into the index. git commit turns the index into a permanent snapshot. git restore copies backwards. Keep the three columns in your head and the rest follows.

PlaceWhat it isHow things get there
Working treethe files you are editing right nowyou edit them
Index (staging area)what the next commit will containgit add
Repositorythe snapshots that are kept forevergit commit

Why the middle one exists

Most tools have two places: what you have and what you saved. Git's third one lets you decide what goes in this commit — you fixed a bug and also renamed a variable in another file, and those are two different commits. You stage one, commit it, stage the other, commit that.

This is what makes a git history readable a year later, and it is the single habit that separates a useful history from a list of "update".

Setting it up, once

your name goes into every commit you make
git config --global user.name  "Ulvi Shabanbayli"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

git --version
What the terminal in these lessons is

The panel on the right runs a small git written for this course. It is not a recording: it builds real git objects and hashes them with SHA-1, so the ids you see are the ids the real git prints for the same content. What it does not have is a network, a file system, or the parts of git the lessons never use — and it says so plainly when you ask for one of them.

The vocabulary, in one place

WordMeans
repository (repo)the project, plus all of its history
commitone snapshot, with a message, an author and a parent
brancha moving name for one commit — nothing more
HEADwhere you are: usually a branch name
remoteanother copy of the repository, usually on a server
clone / fetch / pushcopy one down · get their new commits · send yours

Practice