I've used git checkout .
to delete local changes from my working index.
Does anyone know what git
is doing under the hood™?
I've used git checkout .
to delete local changes from my working index.
Does anyone know what git
is doing under the hood™?
Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch.
git checkout <branch>
To prepare for working on , switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. Local modifications to the files in the working tree are kept, so that they can be committed to the .
If is not found but there does exist a tracking branch in exactly one remote (call it ) with a matching name, treat as equivalent to
$ git checkout -b <branch> --track <remote>/<branch>
You could omit , in which case the command degenerates to "check out the current branch", which is a glorified no-op with a rather expensive side-effects to show only the tracking information, if exists, for the current branch.
Read more here https://git-scm.com/docs/git-checkout
To prevent data loss, git checkout will give an error if it needs to change a file with unstaged changes.
In other words, if you have two branches with different versions of a file, and you edit that file, then try to switch to the other branch, you will get an error because it will refuse to replace your unstaged changes with the other branch's version.