Git internalseasy0-2 years
A teammate avoids creating branches for small changes because "branching is expensive — it copies the whole project." Is that true in Git, and what does `git branch feature` actually do?
No — that advice comes from a different generation of version control, and in Git it's backwards. A branch is not a copy of the project's files; it's a single small file containing one 40-character hash, sitting in .git/refs/heads/. git branch feature writes that one file and nothing else: no files are duplicated, no objects are created, no snapshot is taken. That's exactly why creating a branch is instant regardless of the project's size, and why teams that treat branches as free — one per task, however small — aren't paying any real cost for it.
A developer runs `git checkout <some old commit hash>`, makes a few commits while poking around, then switches back to `main` without naming anything. Are those commits gone? What actually happened?A developer runs `git reset --hard HEAD~1` on the wrong branch, wiping out a commit they needed. `git log` no longer shows it. Is the commit actually gone, and how would you get it back?