How to Use the SAP Web IDE Git Client
Introduction
This blog post describes the SAP Web IDE Git Client features, from the very simple ones to the most complex. I’ll explain how to use it in the most beneficial way.
The first thing you have to do to work with Git, is to have a Git repository in your SAP Web IDE workspace, which you obtain by cloning (or you can deploy an application to SAP HANA Cloud Platform (HCP), which creates a Git repository for you, but in this post I’ll explain it from the clone option). The SAP Web IDE Git Client can work with any Git server, I’ll use the SAP HCP Git server.
Cloning the Git Repository
When you create an HTML5 application in the SAP HCP cockpit, you get a Git repository.
To clone this repository, click on the created application, select Versioning from the menu on the right [1], and click Edit Online [2]. SAP Web IDE opens showing an external command confirmation dialog box (telling you that the Git repository will be cloned).
Click OK. The Clone Repository dialog box appears. Enter your HCP credentials and click OK. If you select Remember Me, your credentials are saved until the next time you refresh your browser.
Once the repository has been cloned, you will see it in your workspace [4]. To follow the operation status, from the View menu, select Console.
Publish Changes to Work Collaboratively
So you’ve worked on your files and saved the changes. You now need to publish your changes so that your colleague, we’ll call him Bob, can see them and continue to work on top of your change. For this, you must push your changes.
First, open the Git pane (by clicking the Git pane button on the right menu bar [5]). You will see the modified, added, or deleted files on the staging table. Select the checkbox for the files that you want to publish [6], enter a description for the commit [7] and click Commit [8]. Your changes are committed and ready to be pushed to the Git server.
The repository status changes to indicate that your branch contains one change that the remote branch does not [9].
To push your commit, select Push > origin/master [10]. You could also press the commit and push button [11] instead of pressing commit and then push. Your commit is merged in the Git server (if there are no conflicts).
Update Workspace with the Latest Changes
Now Bob wants to get your changes.
He must click Fetch. His origin/master branch is updated with the changes. He can see the fetched changes on the Changes Fetched dialog box that appears when the fetch is complete. On the Git status area [9] he’ll see that his branch is one commit behind the remote branch – which means that his remote branch contains changes that his local branch does not.
But Bob’s workspace still does not contain your changes. He has to rebase his local branch by clicking Rebase and then selecting origin/master when prompted.
After pressing OK, if there are no conflicts, the rebase operation is completed and Bob will get your changes. Now he can continue to work on the most updated code.
I recommend you fetch and rebase before performing push in order to avoid merge issues.
Staging Table in Detail and the Amend Magic
All your changes appear in the staging table [12] until you commit them. These can be added, deleted or modified files, and also files with conflicts. To see the changes made to the files, double click the line in the table. You can ignore new files – which means that the Git repository will not track changes on those files, and you will not be able to commit them. For the other files, you can open the file in the editor by selecting Edit from the context menu.
If you have any changes you want to discard, click Discard [13] or Discard All [14]. You can also stage all your changes by selecting the Stage All checkbox [15] – this means that the next commit will contain all these files.
If you committed some change but still didn’t push it, and you want to add more changes to the same commit, stage the files that you want to add to the commit, select the Amend Changes checkbox [16] and commit. You don’t need to enter a commit description since the commit you are amending to, already has one.
There are a lot cases to use the Amend option. Let’s say you developed something that works only partially. You still cannot push it, but you want to save it in its current state. In this case, you can commit without pushing and continue with your development. The diff will be only with your new development. In other words, it compares the current state to the committed one. When ready, you can stage your files, amend the commit, and then commit.
The amend option is very powerful but it can also cause trouble if you don’t use it correctly. For example, amending changes to a commit that was already pushed and merged will cause your next push to fail.
In the next blog I will explain how to work with multiple branches and how to use the Git History pane.
Hi Lidor,
Thanks for the very helpful blog!
I noticed a few things using it git with WebIDE -- did you have similar behavior?
- Password does not save every time, requiring every save to Git to re-enter all credentials.
- Cannot move an existing project into Git, I had to first create a Git-project, then move my existing project into it, for example a sapui5 abap project.
Thoughts?
Hi Gavin,
The password is saved until the next time you refresh your Web IDE browser tab and only if the operation completed successfully.
You cannot copy project into a project, this is a restriction of the Web IDE.
Hope this helps,
Lidor
Hi
there is a way to use submodule in order to share lib/commons code?
If I clone a repo with submodule it seems not to include them on project...
Hi Lidor, Very helpful post. Thanks --jim
Hi Lidor, How about doing the same in local instance of Web IDE? I did try, however not able to follow.
Thanks,
Kevin
Hi Kevin,
It should be the same with the web IDE local installation version.
Did you try it using ssh or https protocol?
Regards,
Lidor
Hi,
Check out the new blog post Working With Multiple Branches with the Git Client
Lidor Tal
Hi Lidor,
Firstly many thanks for your blog.
We are currently assessing how we can leverage GIT features provided by HCP, for SAP Fiori applications which will be deployed to an ABAP repository (deploy option “Deploy to SAPUI5 ABAP Repository”).
We’ve checked several SCN blogs related to GIT and SAP WEB IDE, and we have played around the SAP WEB IDE with the HCP Trial account.
However it seems, we have to deploy the SAP Fiori application to the HCP in order to get access to all the GIT features from the SAP WEB IDE.
My question are:
Many Thanks in advance.
Regards.
Hi,
Currently, to use Web IDE source control capabilities (Git), you must first deploy the application to HCP, and later you can deploy the final version of the app to your ABAP repository. So to answer your specific questions:
I hope this helps,
Ohad
Good
Hi, I do have a question: in this example to me Bob should use his own user/password to retrieve the repository you created. I did some testing and unless I provide my own user and password a collaborator or a team member CANNOT access my repository. So if everybody is using the same user and password it kindda beat the purpose of source control and I check everywhere it does not say how a second developer can clone a repository with its own user and password instead of the original creator user and password
Thanks so much
Vincent
Hi Vincent,
'Bob' should be a member in the account in order to clone a Git repository from HCP.
BTW - On trial landscape you can have only one user per account.
Regards,
Lidor
Hi,
We are using Web IDE git client to push our code to project portal. Some of colleagues are getting Gerrit code review, but for others pushed code is getting merged in central branch with any Gerrit code review link. Do we need any configuration so that all team members pushed code pass thorough Gerrit code review?
Regards,
Vinayak
Hi Vinayak,
Yes, it can be configured in the clone repository phase by checking the option "Add configuration for Gerrit Change-ID:
Or if a clone is already done a new property can be added under "Git Repository Configuration" called "gerrit.createchangeid" with value "true".
To add new property you can follow this documentation page:
SAP HANA Cloud Platform, Web IDE Developer Guide
Regards,
Offer.
Thanks. It was really helpful.
Hi,
SAP Web IDE is providing new feature 'Fetch from Gerrit' using which we can fetch changes from Gerrit.
Can someone let me know what to be entered in Change input box. I tried all options:
Hi,
Sorry for the late response, I didn't get any notification regarding this question.
In order to fetch from gerrit you should copy the EGit value.
expand download from the top right corner and EGit value
Lidor
Is there a way to avoid entering password every time even if the browser is refreshed in SAP Web IDE Git Push ?
Shalom Tal
We are trying to connect the local on premise Sap Web Ide to our GIT repository.
But what ever user /password we provide we always fail.
BTW no error is shown.
Would appreciate your help here.
regards
Yuval Peery