Learn Git as a set of steps to memorise and you will freeze the moment anything unexpected happens. What you need is to be able to say which box your file is currently in.

The three boxes

  • Working tree — the actual files you are editing right now
  • Staging area (the index) — the waiting room for changes you have declared will go into the next commit
  • History (the repository) — the record that has been committed and will not disappear

git add moves things from the working tree to the staging area; git commit moves them from the staging area into history. That is all.

Translating git status

bash
$ git status
Changes to be committed:      # <- in the staging area
  modified:   app.py
Changes not staged for commit: # <- only in the working tree
  modified:   README.md
Untracked files:               # <- Git does not know about these yet
  notes.txt

All this output does is report the contents of each of the three boxes. Once it means something, the command to type next decides itself.

Making the frightening operations less frightening

As long as you have committed, almost any mistake can be undone. Commit first, then experiment.

git reflog remembers where your commits went even after you delete a branch. Genuinely irreversible operations are very few.

The bare minimum for working in a team

Put one purpose and one purpose only on a branch. Keeping to that alone makes reviews dramatically easier and cuts conflicts.