Posted on 2024-08-02 by Matt.
git checkout docs or git checkout --help
Checkout branch feature-123
$ git checkout feature-123
Checkout branch feature-123, discarding changes if there is a conflict
$ git checkout -f feature-123
Checkout the last branch, tag, or commit you had checked out
$ git checkout -
Checkout commit 513ad35
$ git checkout 513ad35
Checkout tag v3.0.1
$ git checkout v3.0.1
Create a new branch named tmp if and check it out.
Fails if tmp already exists.
$ git checkout -b tmp
Create a new branch named tmp if and check it out.
Resets tmp if it already exists.
$ git checkout -B tmp
Checkout the entire subtree from HEAD.
Effectively discards all changes to tracked files in working dir.
$ git checkout .
Checkout ./src from HEAD.
Effectively discards changes to src in working dir.
$ git checkout src
Checkout ./src from feature-123 and stage changes.
Effectively updates your ./src to be in the same state as it is on feature-123.
$ git checkout feature-123 ./src
Accept all the changes from one side of a conflict.
$ git checkout --theirs .
$ git checkout --ours .