Working With Multiple Branches with the Git Client
One of the most powerful benefits of using Git is the support of multiple branches. In this blog post I’ll explain how to handle multiple branches with the SAP Web IDE Git client (create, remove, reset and rebase branches).
Note: For this blog post I assume that you are already familiar with the basic Git operations in the SAP Web IDE Git client and that you already have a Git repository in your workspace. If this is not the case, please read to How to Use the SAP Web IDE Git Client
A short terminology alignment before we start:
- Check out – Updates the files in your workspace to match the selected branch.
- Remote branch – Remote branches act as bookmarks to remind you where the branches in your remote repositories were the last time you connected to them.
- Branching – A diversion from the main line of development so that work can continue without altering the main line.
- Porting – The action of copying commits with code from one branch to another.
Create and Check Out a New Branch
The first thing you have to do when working with multiple branches is to create a local branch in your Git repository.
To do that, click the plus button in the Git pane . In the dialog that opens, select the source branch  for the new local branch (the code in the new branch will be based on the source branch), provide a branch name , and click OK . The new branch will be created and checked-out for you.
Currently, the SAP Web IDE Git client supports only one branch based on a remote branch, therefore, the Branch drop-down list does not contain the remote branch on which your local branch is based. (I will update this blog once this is available).
I choose to create a local branch based on the local master branch with the name newFeature.
On the newFeature branch I will create a new file called FileInNewBranch.js and commit it.
Now, when I check out the master branch (switch branch ) you can see that the FileInNewBranch.js file is not there .
This means that I have multiple versions of code on the same workspace. I can easily switch back to newFeature where I can add more content, creating a new commit, or amend my previous commit.
There are several ways to port a change, I’ll describe here the rebase option and you can learn about the cherry-pick option in the Git History Pane blog post.
Let’s say that I have several commits on my newFeature branch and I want to port them to the master branch, so I’ll have the commits from the newFeature branch on the master branch. I check out the master branch (by selecting it from the Branch drop-down list ) and click Rebase . In the Rebase dialog I select the newFeature branch  and click OK . Now all my commits from the newFeature branch are ported to the master branch.
As you can see, my local master branch contains 2 commits  that the remote branch (origin/master) does not. (These are commits I ported from the newFeature branch.) You can also see that the 2 new files  I created on the newFeature branch are also on my master branch.
If you don’t need the created branch any more you can easily remove it by pressing the minus button . Make sure that you really want to delete the local branch. This operation will remove the copy version (and all additions made to it) from the repository and it cannot be undone.
Let’s say you’ve performed one or more commits and now you want to reset the status of your local branch to what it was before the commits. Click the Reset button . In the dialog that opens, select the branch whose status you want your branch to be reset to. Before clicking OK, select a reset type.
Reset mixed will keep your changes in the workspace (even if they come from multiple commits) and reset your commit’s status.
Reset hard will reset the commit status and will reset (remove) all the changes in your workspace. You cannot undo this operation, make sure that you really want to remove your changes/commits before using this operation.
In this example I mixed  the master branch to the origin/master  branch.
I have the FileInNewBranch.js file and the FileInNewBranchForCommitB.js file in my staging table  (uncommitted changes) and my local branch has the same status as the remote branch.
It is also possible to reset your branch against some other branch (not the one that your branch is based on), but this is an uncommon use case.
This blog post has shown you how to work with multiple branches and perform the following operations:
- Create Branch
- Check Out
- Remove Branch
In the Git History Pane blog post I describe how to use the Git History pane and the cherry-pick option.