Skip to Content

Introduction

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 [1]. In the dialog that opens, select the source branch [2] for the new local branch (the code in the new branch will be based on the source branch), provide a branch name [3], and click OK [4]. 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.

/wp-content/uploads/2015/06/1_735704.png

On the newFeature branch I will create a new file called FileInNewBranch.js and commit it.

/wp-content/uploads/2015/06/2_735705.png

Now, when I check out the master branch (switch branch [5]) you can see that the FileInNewBranch.js file is not there [6].

/wp-content/uploads/2015/06/3_735706.png

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.

Rebase

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 [7]) and click Rebase [8]. In the Rebase dialog I select the newFeature branch [9] and click OK [10]. Now all my commits from the newFeature branch are ported to the master branch.

/wp-content/uploads/2015/06/4_735707.png

As you can see, my local master branch contains 2 commits [11] 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 [12] I created on the newFeature branch are also on my master branch.

/wp-content/uploads/2015/06/5_735708.png

If you don’t need the created branch any more you can easily remove it by pressing the minus button [13]. 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.


Reset

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 [14]. 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 [15] the master branch to the origin/master [16] branch.

/wp-content/uploads/2015/06/6_735709.png

I have the FileInNewBranch.js file and the FileInNewBranchForCommitB.js file in my staging table [17] (uncommitted changes) and my local branch has the same status as the remote branch.

/wp-content/uploads/2015/06/7_735710.png

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
  • Rebase
  • Reset
  • 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.

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Ritushree Saha

    Hi Lidor Tal,

    Thanks for the useful information and steps.

    We have a requirement to create two remote branch. Is it possible as from webide we are not getting any option . We have administrative access .

    Please do let me know .

    Thanks

    Ritushree Saha

    (0) 
  2. Ram Ganti

    I have created git repository and done couple of commit to it.

    I can’t able to clone the same repository from other trail account.

     

    It is giving error as “Service not found”.

     

    Please can you suggest what would the problem.

    (0) 
    1. Uri Nizan

      Hi Ram,

       

      What do you mean by other Trial accounts?

      Where is the Git repository? on GitHub or Cloud Platform?

       

      Thanks,

      Uri

      (0) 
  3. Adam Kvist Lamaa

    Hi Lidor,

     

    The branch feature does no longer seem to work properly in the Web IDE. When creating a new file in a feature branch, the file is still displayed when I switch to the master branch.
    Is this a known issue?

    (0) 
    1. Uri Nizan

      Hi Adam,

      Which version of Web IDE are you using?

      Is it the multi-cloud version (aka Innovation) or the standard Web IDE?

       

      Thanks,

      Uri

      (0) 

Leave a Reply