Git tutorial


This chapter will point out the parts which may change in time and are essentially variables whenever they occur in text / images. These variables will be surrounded by brackets [ and ].
Gitlab version is 9.4.5 at the last edit of this document.
NB! The sample values used in this document should be replaced in your case.

Variable Description
Uni-ID This is username which is used by multiple services in TTU e.g. gitlab. Earlier versions of this were in the following format: firstname.surname. Newer version of Uni-ID has fixed length of 6 e.g. xxyyyy where xx is 2 first characters from first name and yyyy first 4 characters from surname. Some characters may be replaced e.g. Estonian ‘ü’ -> ‘u’. In this document Uni-ID will have a value of josmit  (Derived from John Smith).
repository Repository in gitlab is ‘Project’ name. This may vary from course to course meaning that it will be specified by the lecturers. For example in the Programming I course the name should be course code all in lowercase letters e.g. iag0581 (for the older courses – 2016 and older) or iax0583  (for 2017 and newer). In this document project name test  is used.

Installing git

This chapter will describe how to set up your system for git usage.


Windows installation will ask you multiple things, just leave the default settings as is and click “next” until you can click “finish”. Then click finish and you’re done.
For a video tutorial one can follow this [ link ] .
Aforementioned tutorial also shows how to do basic git configuration (this will be covered in next chapters).

Other platforms

In linux and mac you can verify if you have git by typing “git –version” into terminal.


If you don’t have git then follow the tutorials given in the [ link ] .

Gitlab login

For you to create git project you need to log into gitlab ( ). To log in with your Uni-ID make sure you have Uni-ID selected.


If you don’t have Uni-ID log into [ link ] with your ID card and set up your Uni-ID.

Create project

To create a new project one should navigate to and click green “New project” button. If you don’t have any previous projects you should see this selection in the center of the page as shown on the figure.


If you already have created a project you find the button on the right side of the page as seen on the figure.


When creating new project make sure you :

  • Name it as [repository].
  • Set visibility as Internal


Next you shall be forwarded to the front page of your project. This is the url you should give us (Your project URL), in this example it is . In your project page under the “Git global setup” section you find the necessary commands for git configuration. These are the commands you should enter in the next chapter.


Configure git

To configure git open terminal window in the directory you wish to put your project in. In computer class this should be on your P drive!
Windows users should go to directory you wish to save your project in and right click in the folder and click “Git Bash Here”


For basic configuration type in the commands shown in your Git global setup. For you should enter your full name and for the email you used to create an account. If you used Uni-ID for login, your email is used. It is very important that this info matches. To verify your data go to your [ profile settings ] .


Create SSH key (optional)

Using SSH key is recommended because it offers you a way to push / pull code without entering your credentials every time. One can think of it as a fingerprint.
To create an ssh key you must type the following (NB! Check that your spaces are correct!):

  • ssh-keygen -t rsa -C “”
    • Email should be the same as on the setting!
  • * press enter *
    • Then the key will be saved in your home directory ( ~/.ssh/ )
  • * press enter *
    • If you type password here, you will always be prompted for password.
  • * press enter *
  • cat ~/.ssh/
    • This command will print the ssh public key on terminal.



Now you should add this key to your [ SSH keys ] in gitlab.


Make sure that there is no newline after the email address! Then press “Add key”
You have now successfully added SSH key!


Cloning project

This chapter will describe how to clone using different methods. Using SSH you need to do the SSH key setup in previous chapter.

Cloning using SSH (preferred)

The first 2 commands used for this step are shown on the Create a new repository section in your project directory.

Then you should use the git clone command, in our example it would be “git clone[Uni-ID]/[repository].git”. You can get this URL in your project directory:


You shall be prompted with a question whether you wish to continue connecting to the server, you should type “yes” and then press enter.


After successfully cloning the repository you must go to that directory by typing “cd [repository]


Cloning using HTTPS

The first 2 commands used for this step are shown on the Create a new repository section in your project directory.

Then you should use the git clone command, in our example it would be “git clone[Uni-ID]/[repository].git”. You can get this URL in your project directory:


You shall be prompted with Username and password. Your username could be found in the URL, in our example it is “User”. When you type your password in linux password fields will not be filled with asterisks (*)!


After successfully cloning the repository you must go to that directory by typing “cd iag0581”


NB! If you cloned with HTTP/HTTPS you will be prompted with username and password each time you try to clone / push / pull / …

Working process with git

This chapter will describe the workflow with git. To use git in windows you must open the directory where your project is and right click in there and then press “Git Bash Here”.
To use these commands your working directory must be the project directory.

View new / modified / deleted files

To view changed files (modified / new / deleted) type “git status”.
New / untracked / modified files will be shown with red font.


Staged files will be shown with green font.


Adding files to staging area

To add all new / modified / deleted files into staging area type “git add –all”. To add files to staging area means to save these files at current state. This enables users to view these files as they were in future.


You can also add files separately to staging area by typing “git add [filename]”

Commiting staged files

To confirm the saving user must commit these changes by typing “git commit -m “message””, where -m will indicate that message parameter will be added with this commit. By executing this command user will commit all staged files with the same message. User can also commit files seperately with different messages by specifying file: “git commit [filename] -m “[message]”
After typing the command to commit all staged files the output should be something similar:


Pushing commits to gitlab server

This action is required to have the latest version of your files accessible in server. It is not necessary to do this after every commit however it is recommended to do after finishing your programming session.
To push changes into gitlab server type “git push


Now your files are pushed into server and the lecturers can access them and grade your homework / lab work.
All of the commits can be seen in your commits at [ Gitlab ] in our example the url is ( ).


View commit history

To see the commits made in this project one can type: “git log” or “git log –pretty –oneline –graph”. First of which will show the full SHA1 hash, author, date and message of the commit. Second command will display the commits as a graph with short (partial) SHA1 hash and a message.



Typing the latter command every time is time consuming therefore it is reasonable to create an alias for that command. In this example the command shall be called “hist”. It can be done by typing: git config –global alias.hist “log –pretty –oneline –graph”


Getting latest version from server

To get the latest version of files from server type “git pull”.


Note that ls shows the contents of current folder.

Special files

This file is usually added to the root directory of the repository. This file is a markdown file which is essentially a text file that supports styling. Project page will display the file contents. See markdown cheatsheet and online markdown editor .


This file is added to the root directory of the repository. The contents of this file will dictate which files won’t be tracked. It is a desired usage for binary files such as .exe etc.

Adding specific file to .gitignore

Lets say that we have an files that contain passwords or API keys etc that we don’t want to share with other people. In order to do this, we must first create and add a file called .gitignore to our repository.


After that open .gitignore file any regular text editor and add the name of the file that we don’t want push to git. In our example we don’t want to push file called config.php





Result: no config.php file was added.

Adding file types to .gitignore


Comments in .gitignore

  • Lines that start with # serves as a comment

More information about .gitignore 

Working process with Web interface

To operate with web interface one must first log in at .

Adding new files / directories

To add new files first navigate to your project and then press “Files”.

Then we can add files by pressing “+” button


In this example we are adding a new directory “lab2”


After pressing “Create directory” you will have added new directory with a commit message “Add Lab3”.

Modifying files

To modify file, from “Files” menu navigate to the file that needs modifications, then press “Edit” button.


After making your modifications press “Commit Changes”.


Now you have successfully changed your file and there is a history of it.


We shall be giving feedback by creating issues, your task is to fix these issues in order to get points.
You can find issues in your project directory:


The other way to see issues is on the navigation bar on the top right corner of the page. The button with ‘#’ Icon signifies issues and checkbox signifies todo items. For issues both of them are shared. Number next to the icon shows how many items are in those categories (for issues it means open issues).


To view issues click on “Issues” and you should see something like this:


To view todo items click on “Todos” and you should see something like this:


After clicking on the title (bold text) of the issue you should see more details.


Once you have corrected the mistakes pointed out in this issue return to this page, write what you’ve done and mark this issue as complete by clicking on “Close issue” In your commits it would be wise to use format “Fix [issue number] [additional info]” e.g. “Fix #1 added image”. After commiting with such a commit message, Gitlab will automatically close the issue.

After closing the issue you can see these issues under “All” tab or “Closed” tab.


Now you should let us know that you have fixed issue and we will recheck your work.

NB! If the issue is closed automatically or by you there is a chance that instructors might not find the issue as resolved and it will be reopened.

Enable issue notifications

To receive email notifications about opened issues you must first enable them. Navigate to your [ notification settings ] page .
Click on the arrow button and then on “Custom”


In custom issue menu you should enable the following notifications:


Email notifications will be sent on your email specified in Notification email tab.
Same settings should be applied to Project notifications. This is located on the same page but on the bottom right corner.


Server certificate verification failed

If you are cloning / pushing / pulling and you see a similar message as in the figure below means that there are errors verifying SSL certificate (used for encrypted HTTPS traffic).


Solution to this error message from client side is to type in the following command:

git config --global http.sslVerify false



  • Git as a Sci-Fi story [ Video ]

2 thoughts on “Git tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.