Skip to content
jsworkbench.
Learning path
Foundations18 min

Repositories and the three states

Understand the idea

A repository is three places for the same files: the working tree, the index, and the commit history.

The idea

A on this platform is a stored history plus the labels that point into it. Creating one writes a row for your account. The address looks like /git/field-notes. Reload the page and the same commits are still there.

What changes

git status compares three places. The is what you just typed. The is the snapshot you have selected. HEAD is the last photo. A file can differ in any of those pairs, and status names which pair.

The three states
PlaceWhat it holdsHow you read it
Working treeEdits that are not staged yetgit diff
IndexThe snapshot the next commit will storegit diff --staged
HEADThe current commitgit show

The command

Sign in, then use Create repository on this page. After it exists, run git status. Then write notes.txt hello, git add notes.txt, and git status again. The file moves from unstaged to staged. git commit -m "start notes" stores the index and the graph gains a node. Hashes here are short platform ids, not Git's SHA-1, and the reference lists every command this terminal actually runs.

The mistake

Check your graph

After the commit, main and HEAD sit on the new node. Reload. The same hash should still be on the graph, because the repository row kept the state.

Your repository

Create your first persisted repository here. git status reads those three states. The graph starts with the initial commit.

Create a repository

Sign in first. A repository is an account object, not a file on this browser.

  1. Step 1

    Create the repository

    Use the form above. That writes the repository for your account and starts main with an initial commit. If it already exists, go to the next step.

  2. Step 2

    See the three states

    Status compares the working tree, the index, and the latest commit. Right now they match.

  3. Step 3

    Edit a file

    In the editor, open README.md. If it is not listed, create it. Replace the text with: Field notes for the week

  4. Step 4

    Read the unstaged diff

    The editor changed the working tree. Nothing is staged yet. The diff is that gap.

  5. Step 5

    Stage the file

    git add copies README.md from the working tree into the index. The editor text is what gets staged.

  6. Step 6

    Read the staged diff

    This is the snapshot the next commit will store.

  7. Step 7

    Commit

    The commit stores the index and moves main.

  8. Step 8

    Confirm the history

    Status should be clean. The log shows the new commit on the graph.

The editor edits the working tree. Start a repository and the files appear here.

Follow the steps. Each command step can be placed in the terminal. Edit files in the editor, then stage them.
Supported command reference
  • init
  • add <path> | add .
  • commit -m "message" | commit --amend -m "message"
  • status
  • diff | diff --staged
  • log | log --oneline | log --graph | log --oneline --graph
  • show [ref]
  • branch | branch <name> | branch -d <name>
  • checkout <ref> | checkout -b <name> | switch <name> | switch -c <name>
  • merge <branch>
  • rebase <branch> | rebase -i <branch> | rebase --edit-todo <pick|drop|reword> <hash> [message] | rebase --continue | rebase --abort
  • cherry-pick <ref>
  • reset --soft <ref> | reset --mixed <ref> | reset --hard <ref>
  • revert <ref>
  • stash | stash list | stash pop | stash apply
  • restore <path> | restore --staged <path>
  • remote | remote add <name> <repo-slug>
  • clone <repo-slug> | git clone <repo-slug> | git fork <repo-slug>
  • fetch [remote] | pull [remote] [branch] | push [remote] [branch] | push --force [remote] [branch]
  • blame <path>
  • reflog
  • tag | tag <name> [ref] | tag -d <name>
  • bisect start | bisect good [ref] | bisect bad [ref] | bisect reset
  • config <key> <value> | config --list
  • write <path> <text> (workbench: edit the working tree)
  • issue new "title" | pr new <source> <target> "title" | review "comment" | review --request-changes "comment"

Commit graph

No commits yet. git init creates the first one.

Quiz

A quick check for understanding. Retry as often as you like; your learning path stays open.

01Which place does git commit read?
02What does creating a repository on this platform do?

Ready to call this one understood?

Mark this lesson complete to earn 100 XP. You can always revisit it.

Sign in to save progress
Next lesson