git checkout command is used to change branch. Switching a branch is also known as checking out a branch. There are two ways you can use git checkout:
You pass the branch name to which you want to switch to
Before running the command, ensure that you have already created that branch. You can list all the branches using git branch.
$git branch * master testing
You can see that the testing branch is already created, so you can change to it easily.
$git checkout testing Switched to branch 'testing'
You can view the currently active branch by typing git branch:
$git branch * testing master
Now, you can see that the active branch is
When you specify
-b option to git checkout, two things happen:
Let's understand the entire concept with the help of an example:
$git branch * master
You can see that there is no
testing branch. Let's create a testing branch and check it out in a single command.
$git checkout -b testing $git branch * testing master
Now, you can see that the testing branch is created and it is the currently checked out branch.