Study notes · 10% of the exam

Repositories, Staging, Commits and Config

Git tracks content through three areas (working tree, index and repository), and most everyday surprises come from forgetting which area a command touches, how ignore rules match, or which config level wins.

Key points

  1. 1

    git add copies a file's current content into the index; a commit records the index, not your working tree, so edits made after git add are not included until you add again.

  2. 2

    git status --short has two columns: index vs HEAD, then working tree vs index. AM, MM, AD and R each describe a precise state.

  3. 3

    git commit -a and git add -u cover tracked files only; git add -A also stages new files and lets status detect renames.

  4. 4

    .gitignore only affects untracked files. To stop tracking a committed file, run git rm --cached and commit, and treat any committed secret as leaked.

  5. 5

    Ignore patterns: a leading or middle slash anchors to the .gitignore's directory, a trailing slash matches directories, the last matching line wins, and you can't re-include a file whose parent directory is excluded (use dir/* instead).

  6. 6

    Config precedence runs system < global < local (< worktree) < -c on the command line. git config --show-origin and --show-scope show where a value comes from.

  7. 7

    .gitattributes is committed with the project: text eol=lf, binary, diff and merge drivers, and export-ignore apply to everyone, unlike each developer's core.autocrlf.

Common traps

  • logs/ followed by !logs/keep.txt keeps the file ignored; write logs/* then !logs/keep.txt.

  • git clone --depth 1 ../repo ignores --depth for local paths (use file://), and --depth implies --single-branch.

  • Git doesn't track empty directories, and it doesn't record renames; rename detection is content-based with a 50% similarity default.

Test yourself on Repositories, Staging, Commits and Config

Ten questions, with the answer and explanation after each one.