The 4 States of Git
Git isn't just a backup tool; it's a state machine. Most confusion comes from not knowing which of these four "areas" your changes currently reside in.
Untracked or modified files on your disk. Git knows they changed but doesn't "own" them yet.
A middle ground. You've marked these changes to be included in the next snapshot.
The committed history on your machine. Your work is safe here locally.
The shared truth (GitHub/GitLab). Where your team sees your work.
The Searchable Git Bible
| Command | Impact Zone | When to use it |
|---|
"Oh no, I broke it" (Disaster Recovery)
Git is almost impossible to break permanently. Here is how to undo the most common "mistakes".
Undo the last commit (keep changes)
git reset --soft HEAD~1
Moves changes back to the Staging area. Perfect if you forgot a file or made a typo in the message.
Rescue "deleted" work
git reflog
Git's secret diary. It records every move you make, even if you delete a branch. Find the hash and git checkout [hash] to bring it back.
Interactive Rebase (Clean history)
git rebase -i HEAD~3
Squash 5 messy "wip" commits into one clean feature commit before pushing.
Interactive Git Flow
Click the commands to see how they move your files through the 4 states.