The operation of the branch allows for the creation of another line of development. We can use this function to prevent the development process into two distinct directions. For example, we have released version 6.0 and may want to create a branch so that the 7.0 feature upgrades are kept separate from the 6.0 bug fixes.
Tom creates a new branch using the command of the git branch
[jerry @ CentOS src] $ git branch new_branch
[jerry @ CentOS src] $ git branch
* king
new_branch
A new branch was built; Tom used the git branch command to list the available branches. Git shows a star sign in front of the currently tested branch.
Switch between Branches
Jerry uses the exit git command to switch between branches.
[jerry @ CentOS src] $ git out new_branch
Switch to 'new_branch' branch
[jerry @ CentOS src] $ git branch
the king
* new_branch
Shortcut for building and transforming a branch
In the example above, we have used two commands to create and modify branches, respectively. Git provides –b option with an exit command; this function creates a new branch and then switches to a new branch immediately.
[jerry @ CentOS src] $ git checkout -b test_branch Switch to new branch 'test_branch'
[jerry @ CentOS src] $ git branch
the king
new_branch
* test_branch
Remove Branch
The branch can be removed by providing the D option at the command of the git branch. But before removing an existing branch, switch to another branch.
Jerry is currently in test_branch and wants to delete that branch. So you change the branch and remove the branch as shown below.
[jerry @ CentOS src] $ git branch
the king
new_branch
* test_branch
[jerry @ CentOS src] $ git exit master
Switch to 'master' branch
[jerry @ CentOS src] $ git branch -D test_branch
Removed branch test_branch (number 5776472).
Now, Git will only show two branches.
[jerry @ CentOS src] $ git branch
* king
new_branch
|