Git checkout: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 36: Line 36:


This creates a new local branch and simultaneously switches to it. Optionally, you can explicitly specify a root commit. If not specified, it's the HEAD of the current branch. Note that the operation does not create a corresponding branch in the origin repository, for that you must [[Git_branch#Publish_a_Local_Branch_in_a_Remote_Repository|explicitly publish the local branch in the remote repository]].
This creates a new local branch and simultaneously switches to it. Optionally, you can explicitly specify a root commit. If not specified, it's the HEAD of the current branch. Note that the operation does not create a corresponding branch in the origin repository, for that you must [[Git_branch#Publish_a_Local_Branch_in_a_Remote_Repository|explicitly publish the local branch in the remote repository]].
=Overwrite a File in the Working Tree=
git checkout <pathspec>

Revision as of 00:27, 30 July 2019

Internal

Overview

Check Out the HEAD of a Branch

git checkout <branch-name>

This has the semantics of switching to the designated branch.

Checkout a Tag into a Detached HEAD

The following command checks out a specific tag - technically the commit that corresponds to the given tag - into a detached HEAD branch.

git checkout <tag-name|commit-id>
git checkout RESTEASY_JAXRS_2_3_2_FINAL

Reposition the local repository on the HEAD of a branch

git checkout <other-existing-branch-name>
git checkout master

Convert a Detached HEAD into a Named Branch

While being in a detached HEAD situation:

git checkout -b <name-of-a-new-branch>

Create and Check Out a New Branch in One Operation

git checkout -b <new-local-branch-name'> [root-commit]

This creates a new local branch and simultaneously switches to it. Optionally, you can explicitly specify a root commit. If not specified, it's the HEAD of the current branch. Note that the operation does not create a corresponding branch in the origin repository, for that you must explicitly publish the local branch in the remote repository.

Overwrite a File in the Working Tree

git checkout <pathspec>