Creating Git Branches

Objectives

After completing this lesson, you will be able to:

  • Create Git branches

Work with Git Branches

Business Example

In this exercise, you will learn how to work with branches.

Note
SAP BTP Platform and SAP Business Application Studio are cloud services. Due to the nature of cloud software, the naming of fields and buttons, as well as the content of the steps, may differ from the exercise solution provided here.

Task 1: Create and Work with a Feature Branch

Steps

  1. Log into your SAP BTP Platform account and open the SAP Business Application Studio.

    1. Perform this step as shown in a previous exercise.

  2. 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.

    1. Open the command palette, by choosing ViewFind 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).

    2. Execute the command Git: Checkout to...

    3. Choose Create new branch…

    4. Enter featureA into the input field and press the Enter key (on your keyboard).

    5. Open the Git view and observe that the new branch is selected now.

  3. Add a new folder with the name util to your ux402_repository project webapp folder.

    1. From the context menu of your ux402_repository project webapp folder, choose New Folder.

    2. Enter util and press the Enter key (on your keyboard).

  4. Add a new file with the name Formatter.js to the newly created folder util. Then save your changes and close the file.

    1. From the context menu of your util folder, choose New File.

    2. Enter Formatter.js and press the Enter key (on your keyboard).

    3. Save your changes and close the file.

    4. 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.

  5. Stage and commit your changes to the local Git repository. Use Formatter added as the commit message.

    1. 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.

    2. Now, stage all changes. You can stage the Formatter.js file directly by choosing its + symbol (Stage Changes). Now the Formatter.js file should be marked as staged (A) and located under Staged Changes.

    3. 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.

  6. 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.

    1. Open the command palette, by choosing ViewFind Command… or pressing F1 (on your keyboard).

    2. Execute the command, Git: Checkout to...

    3. Choose main.

    4. 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.

    5. Open the Git view. For the merge, select the three dots symbol (Views and More actions…) and choose BranchMerge Branch…

    6. Choose the featureA branch.

    7. Check the artefacts of your project, which should appear as it is shown in the following figure.

  7. 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.

    Caution
    If multiple people are working on a remote Git repository, you should Pull before you Push, but in this case it is not necessary.
    1. Open the Git view.

    2. Choose the three dots symbol (Views and More Actions…) and then choose Pull, PushPush to…

    3. In the input field, choose origin.

  8. Check the content of your remote Git repository on GitHub.

    1. Visit https://github.com/ and log into your account.

    2. Open your remote Git repository ux402repository.

    3. Observe the content of your repository.

    4. To see the four commits, click on the clock symbol.

Log in to track your progress & complete quizzes