Git Tutorial

Git is free, open-source software for managing small to large projects. It is used to manage projects on a version-based basis.

This should be understood as a tutorial with the most common commands. Test and try out the commands and their handling in small test scenarios BEFORE you start working on production systems!

Git Client

Installation on Windows

The Windows Git client Git for Windows can be downloaded from https://gitforwindows.org/. Normally, it can be installed in the default folder.

 

We recommend using TortoiseGit (see below) as a graphical interface for Git on Windows. If you want to use it, you can deselect the Git GUI Here option in the installer.

 

If you want to use a specific editor (e.g. Notepad++), you can configure this here.

 

If there is no specific reason for you to change the following setting, the default is recommended.

 

Verwendung des SSH Clients - © ICT und Digitalisierung Montanuniversität Leoben

Verwendung der SSL Bibliothek - © ICT und Digitalisierung Montanuniversität Leoben

Umgang mit Zeilenumbrüchen - © ICT und Digitalisierung Montanuniversität Leoben

Einstellung der Eingabeaufforderung - © ICT und Digitalisierung Montanuniversität Leoben

Experimentelle Funktionen - © ICT und Digitalisierung Montanuniversität Leoben

Installation under Linux

On most Linux distributions, the Git client can be easily installed via the package manager.
 

Apt-based systems

e.g. Debian, Raspbian, Ubuntu, etc.

# apt install git
 

Yum-based systems

e.g. Red Hat, Fedora, CentOS, etc.

# yum install git
 

Compiling the source code yourself

If necessary, the source code can also be compiled and installed yourself – simple instructions for this can be found at:

Installing Git from git-scm.com:https://git-scm.com/book/de/v2/Erste-Schritte-Git-installieren

Use in the command line

Without any additional tools or IDE integration, Git can be easily used via the command line of the respective operating system. For example, Command Prompt, PowerShell or Git Bash on Windows (installed by the Git for Windows installer) or Bash on Linux. ## Setup before first use If Git has never been used on the computer before, it is necessary to configure the global user and their email address.

$ git config --global user.name ‘[My User Name]’
$ git config --global user.email ‘[User @ Mailserver . TLD]’

The square brackets and their contents must be replaced accordingly. For example

$ git config --global user.name ‘Melanie Amirah’
$ git config --global user.email ‘melanie.amirah@unileoben.ac.at’
 

Checking out a repository that exists on the server

The clone command can be used to retrieve an existing repository, creating a local copy in the process.
$ git clone [repository URL]

The square brackets and their contents must be replaced accordingly. For example
$ git clone https://git.unileoben.ac.at/howto/git
 

Pushing a local directory to a repository

First, use the cd command to change to the appropriate directory. Then The init command is used to create a local repository for an existing directory. To upload this to a server, add the appropriate server with remote add, add the relevant files with add, combine them into a package with commit, and finally transfer them to the server with push.

cd my_gitlab_documentation
git init
git remote add origin https://git.unileoben.ac.at/howto/git
git add .
git commit -m ‘Initial commit’
git push -u origin master

Use with different tools

Git with Windows Explorer extension (TortoiseGit)

TortoiseGit (https://tortoisegit.org/) is a very easy-to-use extension for Windows Explorer that allows you to use Git without the command line.

Check out a repository that exists on the server

Mit Git Clone… kann ein bestehendes Repository abgerufen werden - © ICT und Digitalisierung Montanuniversität Leoben

Pushing a locally existing directory to a repository

Mit Git Create Repositorty here… kann ein neues Repository aus einem bestehenden Verzeichnis erstellt werden - © ICT und Digitalisierung Montanuniversität Leoben

Git with MATLAB

Since MATLAB R2014b, there has been Git integration in MATLAB, which allows you to manage projects in Git without using the command line.