Free lesson

What git actually is

Not a backup button. Open it up and see the snapshots, fingerprints and objects inside, in a real terminal.

12 min7 steps

In this lesson you will

  • What git is, and how it differs from GitHub
  • Run your first commands in a terminal
  • Take snapshots and look inside them

Words you'll meet

Repository
A folder whose history git keeps, in a hidden .git folder.
Hash
A fingerprint worked out from content. Same content, same hash.
Commit
A snapshot of the whole project, with a message and a pointer to the snapshot before it.
Terminal
A window where you type commands and the computer replies in text.
Start the lesson

The lesson, step by step

Each step teaches one idea, then hands you a real terminal to try it on. The exercises run in your browser.

  1. Step 1 of 7

    Not a backup button

    Every team that skips version control ends up with folders like pipeline_final_v2_REALLY_final.sql. Nobody knows which copy is current, or what changed between them.

    Git fixes that. It records snapshots of your whole project over time, in a history kept on your own computer. It works with no internet at all.

    GitHub is something else: a website that stores copies of git projects so a team can share them. Git is the tool; GitHub is one place to put its results.

    Your turn: Which sentence describes git itself?

  2. Step 2 of 7

    Meet the terminal

    Data engineers drive git, and most of their tools, by typing commands into a terminal. You type a command, press Enter, and it replies in text.

    Two commands to start:

    • ls lists the files in the folder you are in.
    • cat pipeline.sql prints a file.

    This terminal runs in your browser. Nothing you type here can touch your own computer, so experiment freely.

    Your turn: List the files in this folder, then print pipeline.sql.

  3. Step 3 of 7

    Start a repository

    A folder becomes a repository (a "repo") when you run git init.

    That command creates one hidden folder called .git. Everything git will ever know about this project, the whole history, lives inside it. Your own files stay exactly where they are.

    Names that start with a dot are hidden. ls -a shows all of them.

    Look at the file list beside the terminal: every file now shows as untracked. Git can see them, but it has not been asked to remember any of them yet.

    Your turn: Turn this folder into a repository, then use ls -a to find the hidden .git folder.

  4. Step 4 of 7

    Fingerprints

    Here is the idea at the heart of git. It names every piece of content by a fingerprint of that content, called a hash: 40 letters and digits worked out from the exact bytes.

    • The same content always gives the same hash, on any computer.
    • Change one character and the hash is completely different.

    git hash-object pipeline.sql shows the hash git would give the file. And echo "text" >> file adds a line to the end of a file.

    >> adds to the end of a file. A single > would replace the whole file, so be careful which one you type.

    Your turn: Get the hash of pipeline.sql. Add a line with echo "-- reviewed" >> pipeline.sql, then get its hash again and compare.

  5. Step 5 of 7

    Take a snapshot

    Saving a snapshot takes two moves:

    • git add pipeline.sql puts the file in the staging area: the list of what goes into the next snapshot.
    • git commit -m "Say what this is" takes the snapshot and labels it.

    A snapshot is called a commit. git status shows what is staged at any moment.

    Why two steps? You might change five files but only want three of them in this snapshot. Staging lets you choose. The message is for people: the colleague who reads the history later, which is often you.

    Your turn: Stage pipeline.sql and commit it, with a message that says what it is.

  6. Step 6 of 7

    Look inside a commit

    A commit is not magic. It is a small text object, stored under its own hash. Git keeps three kinds of object:

    • A blob holds the contents of one file.
    • A tree is a folder: a list of names, each pointing at a blob's hash (or another tree).
    • A commit points at one tree, and adds a message, an author and the hash of the commit before it.

    git log lists commits with their hashes. git cat-file -p <hash> prints any object. You can type just the first 7 characters of a hash.

    Notice the file contents are stored once, by hash. If a file has not changed between two commits, both trees point at the same blob. That is why git history stays small even after thousands of commits.

    Your turn: Run git log to find your commit's hash. Print the commit with git cat-file -p, then print the tree it points to.

  7. Step 7 of 7

    Challenge

    Recap. Change a file, git add it, git commit -m "…". Each new commit records the hash of the one before it, its parent. That chain of parents is your history.

    README.md is still untracked. Time to give the project a second snapshot.

    Your turn: Add a line to README.md, then commit it as a second snapshot. Run git log to see both commits.

Reading is the easy part.

Every step above has an exercise. Do it for real, free, no account needed.

Start the lesson