The Problem Git Solves

What this is. Before version control, keeping history meant copying folders.

`

portfolio

portfolio-backup

portfolio-backup-2

portfolio-FINAL

portfolio-FINAL-actually

`

You have almost certainly done some version of this. It works until you need to answer a question about it, and then it fails completely.

The questions a folder of copies cannot answer.

What changed between these two versions, and why.

Who made this change.

Which version was working before I broke it.

Can I try something risky without endangering what already works.

Can two people work on this at once.

Git answers all five, and that is the actual reason it exists. It is not a backup system. It is a record of decisions.

✦ A commit is a sentence, not a save

The habit that makes git valuable is writing commits that explain WHY. Six months later, updated files tells you nothing you could not see from the diff. Fix search returning results in the wrong order tells you what problem existed and that it is now solved. Your commit history is documentation that writes itself, but only if you write it.

Three places a file can be. This is the model that makes everything else make sense.

The working directory is what is on disk right now.

The staging area is what you have marked for the next snapshot.

The repository is the recorded history.

A change moves working, then staged, then committed. Nearly every git command is about moving between those three.

The three places

COMMANDS

working directory
     |  git add
     v
staging area
     |  git commit
     v
repository

MEANING

what you edited

what you chose to include

what is recorded forever
Compare → Staging looks like a pointless extra step until the first time you have made three unrelated changes and want them recorded as three separate commits. It is what lets you say this part, not that part.
SANKOFA SANDBOX
A real git runs here, against a fake filesystem. Nothing touches your machine.
A portfolio site is waiting in ~/portfolio.
Type `cd portfolio` to look around.
learner:~$

You are not expected to know these commands yet. Run them and watch what changes. The next lesson explains each one.

Try it → Run `cd portfolio`, then `ls`, then `git status`. Read the error carefully: it is telling you this directory is not tracked by anything yet. Then run `git init` and try `git status` again.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Your First Repository →
← Back