Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

checkout is one of the few git commands that makes sense to me. I use it a lot, to get back to a known state, after I screw up my working files with other git commands. E.g.

Copy my changed files to a temporary directory.

Delete my working directory.

Checkout the latest version from the repo.

Copy my changed files back.



The article says that git checkout confuses things that could be better accomplished with one of (git restore, git switch, git reset)

What you're doing sounds like git reset/git switch would be fine. I think I'm in favor of what the author suggests, conflating switch and reset/restore seems bad. It's going to take some effort to fix my habits though.


Use `git stash` instead of copying files around manually to save yourself some time.


Parent comment is the quintessential example from the article that most people who know git didn't learn git properly.


Yeah git rubbed me the wrong way from the beginning and I never learned it properly. My way makes the most sense to me. Stash? where? How do I get my files back? None of that is intuitive. I understand my way.


I love git stash, but to be fair, if you've just had Git do something unexpected to your files, I can completely understand why you would not then trust Git to keep your changes safe while you use more Git commands to get back into a sane state! Sometimes simple and well understood is the best way.


Anything can do something unexpected to your files if you don't put effort to understand it. Sure, some things require less and some more effort, but using tools without understanding them, while isn't impossible, isn't exactly a recipe for good outcomes.


Now if git stash would support only stashing one specific file...


  git stash -- filename


or

    git stash push <filename>


The one bad point about checkout is that is one of the few git commands that can destroy data irretrievably, even without --force or -f or so. That is unexpected behaviour.


What you want is 'git reset --mixed'




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: