Branching

When is branching usually used?

- In fact, when you were working, suddenly the boss called the project report with bugs and needed to fix it immediately.

- You have a new feature and want to test it very carefully before incorporating it into the main project.

- You want to do something that does not want to involve the main branch (master).

Performing Branching

For example, your blog needs to add comments feature below the article. You will create a new branch called feature/comments.

$ git branch -b feature/comments

The above command will create a new branch and switch to that branch to work.

Type the command git branch to see the current branch and branch are working. The working branch will have an asterisk (*) in front of it:

$ git branch
master
* feature/comments

To switch back to the master branch, type the command git checkout:

$ git checkout master
Switched to branch 'master'

Merging

After you are sure of your changes in the feature/comments branch. You can pull any changes in this branch to the master branch using git merge.

Note that you must switch back to the master branch before merging the feature/comments branch.

$ git checkout master
Switched to branch 'master'
$ git merge feature/comments

After successfully merging, the feature/comments branch becomes redundant, you can delete it with the following command:

$ git branch -d feature/comments

This part I would like to pause here. In the next part, I will talk about git reset.

I wish you happy learning.

Keywords: Git

Comments