Git checkout

805    Asked by NishiVerma in Devops , Asked on Dec 10, 2019
Answered by Nishi Verma

The git checkout command lets you navigate between the branches created by the git branch. Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. Think of it as a way to select which line of development you’re working on.

The git checkout command may be confused with the git clone. The difference between the two commands is that clone works to fetch code from a remote repository, alternatively checkout works to switch between versions of code already on the local system.

New Branches

Git checkout works hand-in-hand with the git branch. The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off master using the git branch new_branch. Once created you can then use the git checkout new_branch to switch to that branch. Additionally, The git checkout command accepts a -b argument that acts as a convenience method which will create the new branch and immediately switch to it. You can work on multiple features in a single repository by switching between them with a git checkout.

$git checkout -b

The above example simultaneously creates and checks out new branch

Your Answer


Parent Categories