Git tracks every change to your code so you can collaborate, experiment, and recover. The CLI looks intimidating but most of daily work is six commands.
1. The Daily Loop
git status # see what changed
git add . # stage everything
git commit -m "Add login form"
git pull --rebase # update with latest
git push # share your work2. Branching
Branches are cheap. Use them for everything: features, fixes, experiments.
git switch -c feature/signup # create + switch
# work, commit, repeat
git push -u origin feature/signup3. Merge vs Rebase
- Merge β preserves history exactly. Creates a merge commit.
- Rebase β replays your commits on top of another branch. Cleaner linear history, but rewrites commit hashes.
- Rule of thumb: merge for shared branches, rebase for your local feature branch before pushing.
4. Recovery & Undo
git restore file.txt # undo unstaged changes to a file
git restore --staged file.txt # unstage
git reset HEAD~1 # undo last commit (keep changes)
git reflog # find any commit you've ever madeSummary
Commit often, write meaningful messages, branch fearlessly. Git's reflog will save you from almost any mistake β you just need to know it exists.