Now that you are familiar with the Fundamentals of GIT lets have a look at the options available for GIT with SAP Business Application Studio.
SAP Business Application Studio has a local repository for GIT the recommendation is always to have the work saved in remote repositories. Remote repository can be public or private aka Corporate GIT.
For this course we will focus on using the Public GIT in particular github https://github.com/. As mentioned earlier you can use any other if you already have an account or are familiar with the tool.
SAP Business Application studio comes with predefined set of development environments, auto tools, plugins to support Github so no additional tool or installs are required just a few prerequisite that have to be met.
- Account on https://github.com :
Log on to https:// github.com and follow the account creation process step by step.
- Repository on https://github.com :
Once Account is created navigate to repositories in the menu and create a repository.
Once this prerequisites are met you can start to link the Local Repository to Github repository process in the SAP Business Application Studio in your Dev Space.
- Setup your Git user name, email :
git config --global user.email "firstname.lastname@example.org"
git config --global user.name "user_name"
This process is carried out on the root folder Terminal → New Terminal → cd projects
git config –list is used to retrieve the user credentials saved during configurtaion.
- Initialize the local directory as a Git repository :
git --initHere we initialise the Local directory as a Git Repository. This point it is local and not written to linked with the repository
- Add the files in your new local repository :
git add .
Once we have initialised the repository we then can add the files to this repository ready for the first commit.
- Commit the files that you've staged in your local repository :
git commit -m "First commit(Free Text)"
This step commits the stages files to the Local Repository.
- Create a new :Mainbranch.
git branch -M main
This will create a new Branch named Main, this can be any name.
- Provide the Remote Repository Link :
git remote add origin https://<Git-Host-URL>/<full-path-to-repository>
- Push to Remote Repository :
git push origin main
- User ID and Password :
User Name and Password for Git is asked you can enter it here and proceed, to avoid this step for every push we have below options.
- Using Token :
SAP Business Application studio support Personnel access tokens instead of passwords
Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line i.e Personal access tokens function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS
Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS
You should create a personal access token to use in place of a password with the Github UI or with the command line
To create a token, follow the instructions described in the GitHub documentation
Creating personal access token
- In the upper-right corner of Github page,click Settings
- Click Developer settings
- Click Personal access tokens
- Click Generate new token
- Provide a name for the Token
- Select Scopes, Permissions, to use your token to access repositories from the command line, select repo.
Using a token on the command line
git clone https://github.com/username/repo.git
- Caching the Password / Token : . This avoid the efforts to key in the credentials on every push.
Git Credential helper :
Enter below commands once you login successfully when you push first time from Terminal
git config credential.helper cache –timeout=3600000 (time in milliseconds)
git config credential.helper store
To erase credentials use below command i.e to disable this cached username/password for your current local git folder user
git config credential.helper ""
Other option exists but not covered here. Example usage of .netrc
Git using UI option :
In addition to the Command Line option SAP Business Application Studio provides a graphical user interface for executing Git commands and managing your source control and versioning.
Working with Files in a Git Project
Modifying your project content (with or without Git) means creating, modifying, and deleting files. With Git, all of these changes are tracked in your working directory as soon as they are made, for example, when you save a file you have just modified and listed in the File Status area.
Then, for each file, you have the following possibilities:
Staging or discarding can also be done for the entire set of modifications.
The next step is to commit your changes, which will add a next commit to the history of the branch.
The concept of branches in Git, already introduced, will be discussed in more details later on. For now, let’s just consider that you are working on a single local branch, for example, master.
To materialize this workflow, each file is assigned a Git status. This status is represented by an icon in the SAP Business Application Studio for SAP HANA workspace and/or the File Status area of the Git pane. The list of possible file statuses is as follows:
The Conflict (C) status will be discussed later on.
When you commit changes, you add these changes to the Git history and provide a commit description. From this moment on, the Git History pane will include this commit, and provide the identity of who committed, the date, the commit description, and details on which files were affected by the commit. Note that committing changes does not modify your working directory. The committed files are still available for further modification, and the new or modified files you haven’t committed yet are still here for an upcoming commit. You can also discard the changes to these uncommitted files.
The commit description provides important information to allow the readability of your changes, in particular when you collaborate with other developers. You can find a number of blogs and tutorials on how to write a good commit message. The following are recommendations for writing a commit message:
Start with a relatively short subject (50 characters max), using imperative mood
Separate the subject and body with a blank line
Provide info about what the change does, and why (for example, what issue it solves)
If relevant, provide the URL of a related issue or specification in another system (for example, JIRA)
It is possible to amend a previous commit. This allows you to replace the very last commit by a new one, after you have staged additional files. The original commit description is displayed so that you can modify it before committing again.
You must not amend commits that have been shared with other developers, because this would modify a (shared) history on which others might have already based their work.
More information on Git capabilities for SAP Business Application Studio can be found at https://help.sap.com/viewer/9d1db9835307451daa8c930fbd9ab264/Cloud/en-US/265962e20eee43f499516de9011ac2e3.html