.gitignore — files Git should ignore
A plain-text file at your repo root listing patterns Git won't track: `node_modules/`, `.env`, build artifacts. Without it your repo bloats with noise.
Resolution order (each level overrides the previous): $HOME/.config/git/ignore (per-user global), .git/info/exclude (per-repo, not committed), .gitignore files (committed; nearest to file wins). --negation patterns (!file) re-include something previously excluded by the same level.
Pattern syntax: similar to shell glob. *.log (any .log), build/ (only directories), /tmp (only at repo root, not nested), tmp (any depth), ** (zero or more directories), [Dd]ebug/ (character classes), \#literal (escape special chars). Comments start with #, blank lines are ignored.
Already-tracked files: .gitignore only blocks untracked files from being added. To stop tracking something already committed, run git rm --cached <file> (keeps the working tree copy) or git rm <file> (also deletes locally), then commit. Future changes are ignored.
Per-user global ignore: git config --global core.excludesFile ~/.gitignore_global. Useful for editor swap files, OS metadata — things personal to your setup that don't belong in shared .gitignore.
Debugging: git check-ignore -v <path> tells you which .gitignore rule (if any) excludes a file. Essential when patterns aren't behaving as you expect.
Don't ignore secrets after committing: if .env was committed, removing it via .gitignore does NOT erase it from history. Anyone with clone access reads past commits. Rotate the secret and consider git filter-repo or BFG to scrub the history.
Practice
Type the command that *stops tracking* `secret.txt` in Git but keeps the file on disk.
Practice
Match the .gitignore patterns:
Ignore every `.log` file: Ignore the build output folder only:
Grounded on https://git-scm.com/docs/gitignore
Next up
Branches — parallel timelines
A branch is a named pointer to a commit. Cheap to create, cheap to delete. You branch off `main` to work on a feature, then merge back when done.