Lesson 1 of 8

What Git Actually Solves

Learn what is and why it is useful. Instead of keeping copies like final.doc and final_v2.doc, Git keeps every saved version with a name, date and description you can return to.

Git is a version control system: it records snapshots of your project over time. Each snapshot (a 'commit') remembers exactly what every file looked like, who saved it, when, and why. You can view any old version, compare versions, or roll back to one — nothing committed is ever lost.

Three places your files live: the working directory (the actual files you edit), the staging area (files marked to go into the next snapshot), and the (the permanent history, stored in a hidden .git folder). The daily is: edit files, stage them, commit them.

Bash
# Turn any folder into a git repository:
cd my-project
git init

# The .git folder now holds all history.
# Delete .git and it's just a normal folder again.

# The single most-used command — what's changed?
git status

Common question

Do I need version control if I work alone?

Version control is a record of every state a project has been in, with a note on why each change was made. Git keeps that record on your machine as a chain of snapshots identified by content hashes, so nothing depends on a server and nothing can change behind your back. From that record you get the practical powers: look through history, compare any two points, go back to a version that worked, and work on several ideas at once without them getting in each other's way.

The habits worth starting on day one are small: commit when something works, write a message that says why rather than what, and make a branch before trying anything you are unsure about. They cost seconds and let you experiment without fear.

Source: Linus Torvalds wrote the first version of Git in about ten days in 2005, after the Linux lost access to its previous version control tool.

Common mix-ups

Each of these sounds reasonable. Think about why it is wrong, then open the explanation.

  • Git exists to coordinate teams, so someone working alone has nothing to coordinate.

  • Copying the folder to project-final-v2-real is version control enough.

  • A commit stores the differences from the previous commit.

Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.