Hacker News new | past | comments | ask | show | jobs | submit login

git checkout puts files from the repository into your working directory. For convenience, it will also update the HEAD ref if you check out the full contents of a branch.

I'm not sure what's so confusing about it. Are people thinking of their entire git workdir as the repository? I suppose the fact that .git is often in the same directory as the checkout might lead to people not thinking of them as separate entities.




> For convenience, it will also update the HEAD ref if you check out the full contents of a branch.

And updates the index. And sometimes it gets files from the index instead of a commit.

From a workflow perspective, "switch to working on a different branch", "copy some files into the working tree from a different commit", and "resolve all merge conflicts in this file in favor of 'ours' or 'theirs'" are three very different operations. From a low-level perspective they're somewhat similar, but not the same.


> For convenience, it will also update the HEAD ref if you check out the full contents of a branch.

Not quite accurate. From the root of the repo, `git checkout foo -- .` will checkout the entire contents of the branch without updating HEAD.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: