git-checkout(1)
===============
NAME
----
git-checkout - Switch branches or restore working tree files
SYNOPSIS
--------
[synopsis]
git checkout [-q] [-f] [-m] [<branch>]
git checkout [-q] [-f] [-m] --detach [<branch>]
git checkout [-q] [-f] [-m] [--detach] <commit>
git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new-branch>] [<start-point>]
git checkout [-f] <tree-ish> [--] <pathspec>...
git checkout [-f] <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]
git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]
DESCRIPTION
-----------
Updates files in the working tree to match the version in the index
or the specified tree. If no pathspec was given, `git checkout` will
also update `HEAD` to set the specified branch as the current
branch.
`git checkout [<branch>]`::
To prepare for working on _<branch>_, 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
_<branch>_.
+
If _<branch>_ is not found but there does exist a tracking branch in
exactly one remote (call it _<remote>_) with a matching name and
`--no-guess` is not specified, treat as equivalent to
+
------------
$ git checkout -b <branch> --track <remote>/<branch>
------------
+
You could omit _<branch>_, in which case the command degenerates to
"check out the current branch", which is a glorified no-op with
rather expensive side-effects to show only the tracking information,
if it exists, for the current branch.
`git checkout (-b|-B) <new-branch> [<start-point>]`::
Specifying `-b` causes a new branch to be created as if
linkgit:git-branch[1] were called and then checked out. In
this case you can use the `--track` or `--no-track` options,
which will be passed to `git branch`. As a convenience,
`--track` without `-b` implies branch creation; see the
description of `--track` below.
+
If `-B` is given, _<new-branch>_ is created if it doesn't exist; otherwise, it
is reset. This is the transactional equivalent of
+
------------
$ git branch -f <branch> [<start-point>]
$ git checkout <branch>
------------
+
that is to say, the branch is not reset/created unless "git checkout" is
successful (e.g., when the branch is in use in another worktree, not
just the current branch stays the same, but the branch is not reset to
the start-point, either).
`git checkout --detach [<branch>]`::
`git checkout [--detach] <commit>`::
Prepare to work on top of _<commit>_, by detaching `HEAD` at it
(see "DETACHED HEAD" section), and updating the index and the
files in the working tree. Local modifications to the files
in the working tree are kept, so that the resulting working
tree will be the state recorded in the commit plus the local
modifications.
+
When the _<commit>_ argument is a branch name, the `--detach` option can
be used to detach `HEAD` at the tip of the branch (`git checkout
<branch>` would check out that branch without detaching `HEAD`).
+
Omitting _<branch>_ detaches `HEAD` at the tip of the current branch.
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>...`::
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] --pathspec-from-file=<file> [--pathspec-file-nul]`::
Overwrite the contents of the files that match the pathspec.
When the _<tree-ish>_ (most often a commit) is not given,
overwrite working tree with the contents in the index.
When the _<tree-ish>_ is given, overwrite both the index and
the working tree with the contents at the _<tree-ish>_.
+
The index may contain unmerged entries because of a previous failed merge.
By default, if you try to check out such an entry from the index, the
checkout operation will fail and nothing will be checked out.