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).
For example, your blog needs to add comments feature below the article. You will create a new branch called 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:
To switch back to the master branch, type the command git checkout:
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.
After successfully merging, the feature/comments branch becomes redundant, you can delete it with the following command:
This part I would like to pause here. In the next part, I will talk about git reset.
I wish you happy learning.
Categories: Learn programming