Git command `checkout`
Definition
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.
Basic usage
Go to a previous commit
$ git checkout <hash>
Go to a tag
$ git checkout <tag>
Go back to last commit
$ git checkout # or $ git checkout master
Go back to
HEAD
for a file$ git checkout <file>
Advanced usage
Go to parent commit of a previous commit
$ git checkout <hash>^
Go to parent commit of a tag
$ git checkout <tag>^
Go to “grand parent” of a tag/commit
$ git checkout <object>^^
Create a branch and navigate to it
$ git checkout -b <new_branch>
Create a tracked branch and navigate to it
$ git checkout --track <remote>/<branch>
Create a branch, track it with a different name and navigate to it
$ git checkout -b <local_branch> <remote>/<remote_branch>