Working with GIT

25th Apr 2022

You will submit all homework using the GIT version control system.

You can also use this system to synchronize work at home and at home. It will not happen to you that you will sit unnecessarily because you have your homework on another computer. Use the git pull command to pull changes from a remote repository.

Logging in to the worker server

Log in to the machine you will be working on. You have activated access to the school server omega.tuke.sk. Use the [PUTTY] client (https://www.putty.org/) to connect from a Windows machine. Login name and password is the same as in IS MAIS.

If you have a proper command line, use the command to log in:

ssh ab123cd@omega.tuke.sk

After logging in, check what files you have available:

ls

Create a private key

In order to send submissions from the local machine, you must submit Your public SSH key. You can find the key in the file ~/.ssh/id_rsa.pub a to display it, use the cat command.

cat ~/.ssh/id_rsa.pub

If there is no such file, create it with the command:

ssh-keygen

After entering the command, just press ENTER. Do not overwrite the set file paths !

Copy the contents of the id_rsa.pub file to the clipboard. The method of copying text using the clipboard differs from the SSH client used. In the case of PUTTY, you will see the file and mark the contents and copy it to the clipboard by pressing the left and right mouse buttons at the same time.

cat ~/.ssh/id_rsa.pub

Activating a remote repository

Log in to KEMT Git. Use your student login and password (by which you log in to MAIS).

Create a repository to which you will send your assignments (+ New Repository) and its set visibility to "Private" to prevent unwanted matching another entry. Select the 'Visibility' (Make repository private) checkbox.

In the top right menu (=) find the item "/Profile Settings/Settings/SSH and GPG Keys/Add Key".

Use the clipboard to paste the contents of the file ~/.ssh/id_rsa.pub.

Create a local repository

Log in to the working server omega.tuke.sk. If you have entered an SSH key, you can create a local repository that will connected to a remote repository. A local copy of the remote repository create with the command git clone, where you add the URL of the remote as an argument repository, eg:

git clone git@git.kemt.fei.tuke.sk:ab123cd/pvjc22.git

A folder is created that is called the same as the remote repository.

You will submit all entries using this repository. For each entry, you create a new directory and put in it the files that are part of the entry:

cd pvjc22
mkdir du1
vim program.c

To submit the completed assignment, send it to a remote repository and request an automatic evaluation.

Confirm changes

Changes must first be confirmed. To confirm we need the file first add:

git add program.c

and only then perform the confirmation, which is stored in the local repository. The confirmation includes a message describing the change:

git commit -m "works"

As long as the change is simple and concerns files that have been in the past confirmed, we can combine git commit andgit add into one command:

git commit -am "works"

We can check the status of the changes using:

git status

Uploading Files

Submit your confirmed changes with:

git push origin master

the origin andremote arguments no longer need to be entered, so for sending is enough:

git push

Conflict solving

If we use more than one local repository and one remote repository, multiple versions of the same file may be created. Before we start working, it is good to get the latest version from a remote repository:

In the event of conflicts:

We will confirm all changes:

git commit -am "changes"

We will try to get the latest version from a remote repository:

git pull

If a list of conflicting files is displayed, we will edit all of them and decide which version is the correct one:

vim konfliktny_subor.c

We will confirm the changes:

git commit -m "merge"

We will send changes:

git push

Some useful Git commands

Delete a file or directory:

git rm -r directory
git rm file
# Deletion must be confirmed
git commit -m "deleted files"

To move a file or directory within a repository:

git mv file
# The move needs to be confirmed
git commit -m "file transfer"

Check status:

git status

Reverting to previous changes:

git checkout

View confirmed change history:

git log

Manual page view:

git help

Add new changes that remove already committed changes:

git revert

To delete from the committed change history or delete a change area:

git reset

More details

Next Post

Working with GIT