What is a Git Checkout?

About

With a checkout, you can

Specifically, it will check out the files

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 ?





Discover More
Git - Current / working / HEAD / active branch

The current or active branch is: the branch checked out actually in the working tree The current branch is also known as the HEAD branch (in uppercase) that represents the last commit known...
Git - File

File management in Git (blob and not directory) blob object on the local file system or not (ie in the git file system database) See and short status A file (or blob) identifier is the...
Git File Lifecycle
Git - File Status

The status of a file in a working directory is one of: where: State Tracked Description untracked New file unmodified Tracked File is the same as in the last commit modified Tracked File...
Git - Git (executable|command line)

The git executable where: --git-dir is the location of the repository files --work-tree is the location of the work tree Command Description add Add file contents to the index add--interactive...
Git - Local branch

A local branch is a branch that exists only on your computer. tracking branch There are two types of local branches: non-tracking local branches. They are not associated with any other branch....
Git - Submodule (modules)

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. package manager A submodule is materialzied as: a subdirectory in your working directory. with its metadata...
Git - Tag

This page is tagging in git Git has the ability to tag specific points in history as being important. Typically this functionality is used to mark release points (v1.0, and so on). Git uses two main...
Git - Tracking Branch

Tracking branches are local branches that have set their upstream branch. tracking branchreference The local branches have then a direct relationship with their upstream branch that can be: a remote...
Branches Git
Git - Branch

This page talks Branch management in Git. For Git, a branch is: a commit name (ref) that points to the last commit (head) leaf in the commit log (or log) that represents a commit chain Example...
Git - Repository (Directory)

This page is the notion of repository and how it's implemented in Git. The git repository is a subdirectory named .git that contains all repository files. It contains : commit log configuration,...



Share this page:
Follow us:
Task Runner