About
With a checkout, you can
- change the current branch (ie switch branches)
- or extract files/directory from branches into the working tree (file system directory) files. ie:
- Restore the file state from modified to unmodified
- Extract a file from another branch
Specifically, it will check out the files
- from:
- the repository
- for a branch
- into:
Checking out a local branch from a remote-tracking branch automatically creates what is called a tracking branch
Example
Switch branch
git checkout branchName
Restore a file 2 commits back
Restore the Makefile to two revisions back from the main branch
git checkout main~2 Makefile
Restore all unstaged files
For all unstaged files use at the root dir:
git checkout -- .
Restore a specific file
git checkout path/to/file
Restore a series of file and directories
git checkout main -- {path/to/dir,path/to/dir2,path/to/file.json}
Support
error: pathspec '.' did not match any file(s) known to git.
Do you perform the checkout from the root directory ?