Skip to content

GIT

Introduction

For more information on the origin of Git see fourth panel:

Old Days

Tracking changes

Version control

Collaboration

Typical workflow

Below is a very short and totally incomplete example on how to use git. We’re using desktop for your computer were you are viewing or modifying the repository and server where the repository is centrally stored.

existing repository from server

  1. get repository from server to desktop
    1. if this is the first time, use clone: git clone
    2. if it is already cloned, use pull: git pull
  2. modify content on desktop
  3. add modified and new files to the desktop repository: git add
  4. commit all changes to desktop repository with an annotation: git commit -m "<annotation>"
  5. push desktop repository to server: git push

Typically you pull the repository from the server in the morning to get the latest modifications. During the day you will make changes, add and commit them regularly, i.e. after each important change. Before closing the day you push the local repository back to the server.

GitLab

Windows setup

To integrate the use of git with the gitlab server on Windows you can either use the graphic setup or the command-line setup. For both methods you need to install Git. For the graphic method you will also need to install PuTTY and TortoiseGit.

Retrieving the repository from and storing it to the server can be done with the git-commands. Because we communicate with an open server some sort of authentication is needed to restrict access and provide encryption during transport. This can be done with an SSH connection or HTTPS connection. For several reasons which we will not discuss here the SSH method is preferred. In the steps below your system is setup to authenticate your connection to the server via SSH. This means we need to create a SSH key-pair consisting of a private and public key. The private key is stored on your computer and the public key on the server. During the connection both keys are used to authenticate and to encrypt transport.

Note

You can create the private key used for authentication with the gitlab server without password. This is not very safe but makes life a lot more fun!

Graphic setup

  1. install Git

    1. download from here https://git-scm.com/download/win
    2. accept the default settings during installation
  2. install PuTTY

    This package allow you to connect via SSH to remote computers; for more information check: SSH. In this case we will use the PuTTYgen application in this package to create an SSH-key. This key will be used to authenticate your access to the GitLab server.

    1. download from here https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
    2. accept the default settings during installation
  3. install TortoiseGit

    This package integrates git with the Windows explorer for easy graphic handling of all your git actions.

    1. download from here https://tortoisegit.org/download/
    2. accept the default settings during installation and make sure you select the Run first start wizard before clicking Finish TortoiseGit wizard
    3. accept the default settings in the wizard and enter your name and e-mail address which will be used to annotate changes in the repository with your id and click Next TortoiseGit wizard
    4. you could create a SSH key-pair in the wizard but below we will also explain how to create this key-pair with PuTTYgen. Accept the default settings and close the wizard with clicking Finish. TortoiseGit wizard
  4. create SSH key-pair with PuTTYgen

    1. start PuTTYgen PuTTYgen
    2. click Generate
    3. during key-generation you create randomness by moving your mouse inside the gray area (blank area). You will see the green progress-bar moving PuTTYgen generate
    4. store the private key as a .ppk file and remember this location for later use. Choose whether you would like to use a password or not (see Note above)
    5. copy the complete public key as shown in the upper window under Public key for pasting into OpenSSH authorized_keys file: PuTTYgen public
  5. install public key in GitLab

    1. open the gitlab webserver: https://gitlab.tudelft.nl
    2. login with your netid and password
    3. select your account in the top right corner and from the drop-down menu select Settings GitLab settings
    4. on the left side select SSH Keys GitLab ssh keys
    5. paste the public key from PuTTYgen in the Key window and press Add key GitLab ssh keys add
    6. your public key is now saved in GitLab for your account GitLab ssh keys saved
  6. configure TortoiseGit to use the private key for authentication

    We are now ready to clone an existing repository from the gitlab server to our computer with the use of the Windows explorer integration of TortoiseGit and using our stored private key.

    1. find the URL of the repository you would like to clone to your computer via the gitlab website. Select the blue Clone button on the right side and click the clipboard icon next to the Clone with SSH-URL. This will copy the URL to your clipboard.

      GitLab URL

    2. in the Windows explorer go to the location where you would like to clone the repository and right-click. Select the Git Clone... menu-item.

      GitLab clone menu

    3. copy the URL and click the button with three dots ... to select the private key file with the extension .ppk. Click OK to continue

      GitLab clone

    4. the first time you are using this SSH key-pair to connect to the gitlab server you will receive a warning asking you to confirm this is the valid server address. Please read this message and select Yes

      GitLab cache

    5. finally the repository will be cloned as shown in the logging

      GitLab cloning

    6. the git repository is now stored on your computer and can be managed with git via the right-click menu on the directory

      GitLab cloned

As an alternative you can also install and use the SourceTree package which gives you a graphic browser to your repository and allows for easy maintenance of your code:

This program does not have an integration with the Windows Explorer.

Command-line setup