🔀 Git & GitHub Intermediate

What is git notes?

Answer

Git notes allow you to attach additional information to commits without altering the commit itself (preserving the SHA). Notes are stored separately from commits in refs/notes/commits. Usage: git notes add -m "Reviewed by Alice" abc1234 — add a note to a commit; git notes show abc1234 — show note for a commit; git log --show-notes — include notes in log output; git notes edit abc1234 — edit a note; git notes remove abc1234 — remove a note. Notes are not pushed by default: git push origin refs/notes/commits — push notes; git fetch origin refs/notes/commits:refs/notes/commits — fetch notes. In ~/.gitconfig: [notes] displayRef = refs/notes/* to auto-display. Use cases: (1) Add build metadata to commits without changing them; (2) Attach code review results; (3) CI systems annotate commits with test results; (4) Link external ticket IDs to historical commits. Git notes are less commonly used than commit messages but are useful when you need to annotate commits after the fact (e.g., add CVE references to old security commits) without rewriting history.