In this exercise, you will learn how to work with branches.
Task 1: Create and Work with a Feature Branch
Log into your SAP BTP Platform account and open the SAP Business Application Studio.
Perform this step as shown in a previous exercise.
Create a new branch with the name featureA. You can create and check out branches directly through the Git: Checkout command over the command palette of the SAP Business Application Studio.
Open the command palette, by choosing View → Find Command… or by pressing F1 (on your keyboard) and type into the opened input field Git. (A dynamic list with the Git commands will appear).
Execute the command Git: Checkout to...
Choose Create new branch…
Enter featureA into the input field and press the Enter key (on your keyboard).
Open the Git view and observe that the new branch is selected now.
Add a new folder with the name util to your ux402_repository project webapp folder.
From the context menu of your ux402_repository project webapp folder, choose New Folder.
Enter util and press the Enter key (on your keyboard).
Add a new file with the name Formatter.js to the newly created folder util. Then save your changes and close the file.
From the context menu of your util folder, choose New File.
Enter Formatter.js and press the Enter key (on your keyboard).
Save your changes and close the file.
Check to ensure that the artefacts are created correctly. Your folder and file structure should now look like what we see in the following figure.
Stage and commit your changes to the local Git repository. Use Formatter added as the commit message.
Open the Git view and look at the commit section. As you can see, the Formatter.js file is now marked as unstaged (U) and located under Changes.
Now, stage all changes. You can stage the
Formatter.jsfile directly by choosing its + symbol (Stage Changes). Now the Formatter.js file should be marked as staged (A) and located under Staged Changes.
Commit the files that you have staged in your local Git repository. For the commit, enter Formatter added in the Message input field of the Git view and select the Commit button or click on the checkmark symbol. Now, there should be zero changes.
Switch to the main branch by using the Git: Checkout to command. Then merge the featureA branch and the main branch. For the merge, use the Merge… action from the Git view.
Open the command palette, by choosing View → Find Command… or pressing F1 (on your keyboard).
Execute the command, Git: Checkout to...
Check the folder structure and the artefacts of your project. As you can see in the main branch, the new util folder and the Formatter.js file are not displayed.
Open the Git view. For the merge, select the three dots symbol (Views and More actions…) and choose Branch → Merge Branch…
Choose the featureA branch.
Check the artefacts of your project, which should appear as it is shown in the following figure.
Perform a Push request to add the changes to the master branch of your remote Git repository. Use the Push to… action from the Git view.CautionIf multiple people are working on a remote Git repository, you should Pull before you Push, but in this case it is not necessary.
Open the Git view.
Choose the three dots symbol (Views and More Actions…) and then choose Pull, Push → Push to…
In the input field, choose origin.
Check the content of your remote Git repository on GitHub.
Visit https://github.com/ and log into your account.
Open your remote Git repository ux402repository.
Observe the content of your repository.
To see the four commits, click on the clock symbol.