Getting started with Git (in Positron)#
When working on your group projects later on in the semester, you may find Git useful. To make this less of a hurdle, you may want to start using it slowly throughout the semester. The use of Git, however, is not mandatory in this course.
Git is a distributed version control system that tracks changes in your code and helps you to collaborate with others. These instructions are not a Git tutorial, but will get you started with GitLab@UIBK (so no need to create an account with a platform like GitHub, you have one from the university) and Git in Positron. If you want to learn more, you can have a look at two Real Python tutorials:
Installing Git#
First, check if you have Git installed by typing git --version in a terminal window (e.g., in Positron). If the version number is printed to your terminal, you are set. If you get an error that the command is not found, you first need to install Git. You can download the installer from the Git website.
Gitlab@UIBK#
UIBK offers GitLab to both employees and students. If you have not used it before, you first need to go to the Opt in page and sign in to activate your account.
Once you have activated your account, you can log in to the web interface.
The very basic repository scipro_git_start contains only two files: an automatically created README and our script `my_python_script.py’ from Unit 01.
You can create a fork of the repository (upper right corner). This will create a copy of the repository in your account, which you can modify without changing the content of the original repository.
Getting started with Git in Positron#
You first need to install the GitLab extension in Positron. To do so, open the Extension panel (the symbol with the four building blocks in the Activity Bar) and search for GitLab to install it.
Now open the GitLab panel and click on “Authenticate to GitLab instance”, enter “https://git.uibk.ac.at”, and select “Create a token first”. A browser window should open and take you to git.uibk.ac.at. You may want to adjust the expiration date before generating the token. Copy the token into Positron and you are set.
Now you can clone your Git repository. Go to “New” (top-left corner) and “New Folder from Git…”. Copy the HTTPS url of your forked repository (under Code) into Positron and select the local location on your computer where you want to put the directory. This step is identical to running git clone in the terminal.
Take a moment to look into the new local folder on your computer. It should contain the two files from the GitLab repository and a hidden directory .git which marks the folder as a git folder.
Now modify the script my_python_script.py in Positron (e.g., change the value of a). As soon as you save the file with the changes, you should see a little red 1 appear in the source-control icon of the Activity bar. It indicates that one file has been modified. We will see later how we can tell Git to ignore files and not track them.
If you go to the source-control panel, you can commit these changes and push them to the GitLab repository. First, you need to stage the changes by clicking on the plus symbol next to the file name (equivalent to git add my_python_script.py in the terminal). Enter a commit message (e.g., “updated the value of a in my_python_script”) and click Commit (equivalent to git commit -m 'modified the value of a'). The commit message should be something meaningful. Finally, push the changes to the GitLab respository with the sync button (equivalent to git push). You should now see the changes in the online repository and also that your fork is one commit ahead of the original repository.