Git and remote repositiories

On the first round, when you created a local repository and the working copy from your central repository in version control (or when you cloned a repository), the repository included material only for rounds 1-3. Now, course staff has prepared more material, and you should retrieve these new materials.

Course staff has stored the new material in central repository, called student_template_project. You can find the central repository from:

https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/student_template_project

Since Git is a distributed version control system, it is possible to retrieve updates from several central repositories to a local repository. Now you will retrieve the material of the new round from aforementioned student_template_project to your own local repository, from which you will move them to your own central repository.

../../_images/git_jarjestelyt_en.png

On this course, course staff prepares material in student_template_project. You will prepare your solutions in the repository of your own. In addition, every now and then (every week) you will retrieve updates from student_template_project.

To be able to retrieve material from a repository, different from your own central repository, you must set that other repository as remote in your local repository. You can set student_template_project as remote by following the guidance below.

You can do such a operation either in Qt Creator or in command line. Therefore, choose either pair of the following four sections.

Choice 1: command line

Setting a remote repository in command line

Open command line and move to your local repository. Execute the following command:

git remote add <shortname> <url>

where <shortname> is a short, descriptive name for the new remote repository and <url> is the address of if. For example:

git remote add course https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/student_template_project

To test how the above command succeeded, write:

git remote –v

You can see a list of all remote repositories, for example:

course https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/student_template_project (fetch)
course https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/student_template_project (push)
origin https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/user_id.git (fetch)
origin https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/user_id.git (push)

If everything goes well, you need to do the above kind of remote addition only once during the course.

Retrieving new materials from the remote repository in command line

After setting a remote repository, you can retrieve updates from it to your local repository by writing:

git pull <remote> <branch>

where <remote> is the name of the remote repository that you gave above, and <branch> is the branch of the remote repository, from which you want to retrieve the updates.

Note that the above command starts a text editor set for Git (vi by default). In the text editor, you will write a merge message describing why you have merged. This happens in the same way as writing commit messages, which we have learned earlier. (If you happen to end up in vi editor, you can exit from there by writing ”:wq”.)

For example, the command described above can be executed as:

git pull course master

We have not considered Git branches in this course, they are mainly material of the next programming course. The only branch so far is master.

The above action is needed whenever course staff has delivered new material in student_template_project, typically at the beginning of each round.

Alternatively (if you do not want to write a merge message in an editor) you can, instead of pull, do the same action in two phases as:

git fetch <remote> <branch>
git merge <remote>/<branch> -m "Write a message here"

From above, you can conclude that git pull is actually the same as git fetch + git merge.

Choice 2: Qt Creator

Setting a remote repository in Qt Creator

In Qt Creator, open a project stored in version control to make the necessary menu available. In the menu of Qt Creator, choose the action Tools > Git > Remote Repository > Manage Remotes...:

../../_images/git_manage_remotes.png

As URL, you should have https://course-gitlab.tuni.fi/comp.cs.110-ohj-2_2021-KEVAT/xyz.git or git@course-gitlab.tuni.fi:comp.cs.110-ohj-2_2021-KEVAT/xyz.git, where in the place of xyz you have your user id.

Click ”Add…”, and in the opening dialog at ”Name”, write a short, descriptive name to the new remote (e.g. course or in Finnish kurssi). At ”URL”, write the address mentioned at the very beginning of this material section. After that you can see the new remote repository in the list:

../../_images/git_manage_remotes_new.png

If everything goes well, you need to do the above kind of remote addition only once during the course.

Retrieving new materials from the remote repository in Qt Creator

After adding the remote repository in the list, choose it by clicking the mouse. After that, when clicking ”Fetch”, the updates will be retrieved from the remote repository to your local one. In the case of student_template_project, these updates mean the material of a new round. However, the updates cannot yet be seen the structure of the directory. Click ”Close”.

In Qt Creator menu, choose next action Tools > Git > Local Repository > Branches...:

../../_images/git_branches.png

From the list, choose branch master, just below the newly added remote repository (the line with master, but do not confuse it with another master line). Click ”Merge” (if this takes you to a menu, choose ”Fast Forward”). If your repository is in a state, in which it should be, you should now see the updates in the structure of the directory. In this case, you should see new rounds in the directory templates.

If you have, for example, changed the content of the directory templates, it is possible that the above operation does not succeed. In such a case, contact course personnel.

The above action is needed whenever course staff has delivered new material in student_template_project, typically at the beginning of each round.