Creating branch

We can create branch by using git checkout -b.

For example, the following command creates a new feature branch.

git checkout -b new_feature

This creates a new branch. But actually nothing really changes here until we create new commits. When you git log the commits, you still see the same commits graph. The only difference is now there is a new_feature brands name appears at where the HEAD at.

We will see how branch works when we make changes and commit it. Afterwards, the git log shows commit graph that contains the new_feature and the master, which points to two different commits. This is because we created a branch from where master pointed at and then move forward with new commits.

To make things more interesting, now we go back to where master points at. To go back, we git checkout master.

Now we make some other changes on master and commit it. When we git log to see the commit graph, we see two commits are diverse into two direction, both from the same parent commit but now one is master and the other is new_feature. The HEAD points to the current commit. When we git checkout new_feature again, we can see the HEAD now points to new_feature.