Git Interview Questions
26 Git questions from real DevOps interviews, sorted by seniority: merge against rebase, reset against revert, the reflog, detached HEAD, submodules, and cherry-pick.
What is a Git commit, and what is a Git branch?
A commit is an immutable snapshot of the whole tree, plus metadata: author, message, timestamp, and one or more parent commit hashes. It is not a diff. Git computes diffs on demand by comparing snapshots.
A branch is a forty-byte file containing a commit hash. That is all. git branch feature writes one file; it copies nothing.
That is why branching in Git is instant while it was expensive in older systems, and why the chain of parent pointers is the history rather than the branch names.
HEAD is a pointer to the branch you are on, which is in turn a pointer to a commit. Committing moves the branch pointer forward; HEAD follows because it points at the branch.
Being able to say "a branch is a movable label on a commit" answers a surprising number of later questions on its own.