What should we be careful about with Git checkout?


#1

Question

The command git checkout provides us with a way of pulling down a previously committed file into our working directory. What should we be aware of when using this command?

Answer

git checkout is sometimes referred to as a “dangerous command”. This highlights that it has some gotcha aspects that you should be aware of when utilizing it. For now, it’s most important to understand that any local (in your working directory) changes that you’ve made to the file being checked out will be gone. Git will simply copy the most recently-committed version of the file to your working directory, overwriting your copy. Therefore, it’s crucial that you avoid this command unless you absolutely know that you don’t want your unsaved local changes. Keeping this consideration in mind while using this command will save you the grief of losing your progress when all you wanted was to take a peak at what the previous commit looked like.


FAQ: How to Backtrack - git checkout