Changing branches

In the previous example, we saw that, even after creating the feature branch, the HEAD is still pointing to the master. The command to switch to another branch is as follows:

git checkout <branch-name>

In our example, if we want to change from the master to the feature branch, we have to write the following command:

git checkout feature

The output is as follows:

After running the command, we can see that Git has switched to the feature branch. Now we can run the git branch command again to see where the HEAD is pointing to, as shown in the following screenshot:

The likelihood is that, when you create a branch, you will want to work on that branch straight away, so there is a shortcut to create a branch and then switch to it, as shown in the following code:

git checkout -b newFeature
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.212