Creating a new branch

It is typical when you are using source control management to create separate branches for features or even for bug fixes. The idea is that the main or the master branch should always have the working code and you do development on the branches that may not be stable. When you finish a feature or fix a bug and know that the branch is stable, then you merge the code from that branch to the master branch.

To create a new branch, go to the Git Repositories view and right-click on the repository you want to branch. Then select the Switch To | New Branch... option:

Figure 3.25: Creating a new branch

Note that the Checkout new branch box should be checked. Because of this option, the new branch becomes the active branch once it is created. Any changes you commit are going to be in this branch and the master branch remains unaffected. Click Finish to create the branch.

Let's make some changes to the code, say in the main method of the GitTestApp class:

public class GitTestApp { 
 
  public static void main(String[] args) { 
    System.out.println("Hello Git, from branch bug#1234 !!"); 
  } 
} 

Commit the preceding changes to the new branch.

Now let's check out the master branch. Right-click on the repository in the Git Repositories view and select Switch To | master. Open the file you modified in the new branch. You will observe that the changes you made to the file are not present. As mentioned previously, any changes you do to branches are not committed to the master branch. You have to explicitly merge the changes.

To merge the changes from branch bug#1234 to the master branch, right-click on the repository in the Git Repositories view and select Merge...:

Figure 3.26: Merge Git braches

Select branch bug#1234. This branch will be merged in the master branch. Click Merge. Git will display a summary of the merge. Click OK to complete the merge operation. Now the file in the master branch will contain the changes done in branch bug#1234.

We have merged all the changes from branch bug#1234 to the master and we no longer need it. So, let's delete branch bug#1234. Expand the Branches node in the Git Repositories view and right-click on the branch to be deleted (the selected branch should not be the active branch when deleting). Then select the Delete Branch menu option:

Figure 3.27: Deleting Git branch
..................Content has been hidden....................

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