- Infos im HLRS Wiki sind nicht rechtsverbindlich und ohne Gewähr -
- Information contained in the HLRS Wiki is not legally binding and HLRS is not responsible for any damages that might result from its use -

Git

From HLRS Platforms
Revision as of 17:01, 11 February 2025 by Hpcchris (talk | contribs) (Remove svn part as this is not relvant any more)
Jump to navigationJump to search
Git is a distributed version-control system initiated by Linus Torvalds in 2005. It allows local and remote repositories to store the development history of any kind of documents. It's strengths are its speed, low disk space requirements because of compression techniques as well as failure resistance and built in security because of it's hash based approach.
Developer: Junio Hamano, Linus Torvalds, and many other
Platforms:
Category: Revision Control
License: General Public License (version 2)
Website: Git homepage


Usage

The basic concept of Git uses three levels: Working directory, index and repository. While the working directory is the place the user makes changes, the repository stores the history of changes. The index is used to prepare a new history entry before committing to the repository.

In general Git has a very good help system which provides all the information required including lots of examples and workflows.

git help git
git help COMMAND


To start version control on a directory (and it's sub-directories) execute inside the directory the following command:

git init

This will create a .git directory which will store all configuration data (including the index) and the repository itself.

Commiting changes to your newly created repository is a two state process: First changes have to be added to the index and then the index has to be committed to the repository:

git add my_new_file my_changed_file ...
git commit


You can view the current status of your working directory and index with

git status


Several GUI tools exist which ease up this process. Just try out

git gui


Branches

Git makes it very easy to handle branches, merge changes and distribute data. In Git branches are very cheap so use them for every small change you make in your code! To create a new branch just do a

git branch NAME

To see the current branch use

git branch


To switch to another branch use

git checkout BRANCH

Note, that git will refuse to change to another branch if any changes may be lost.

A very nice GUI to keep a general view of your branches and their relationship is

gitk


Remote repositories

Git is a distributed version control system. This means that it does not rely on a single global repository but on multiple repositories from multiple users - which have all different repositories. This concept means that you only include from other repositories the data/branches you need or want to merge.

If you want to clone a git repository (or another local git repository) use

git clone URL/PATH


To get the latest changes from the repository use

git fetch


To merge the changes automatically to your working tree use

git pull


If you are allowed to write to the remote repository you can push your changes to a remote repository with

git push


Usage on HWW/HLRS platforms

In order to use Git on our platforms vulcan, hunter, ... load the corresponding module

module load tools/git


Using Git provided by University of Stuttgart (TiK)

Introduction

This documentation describes how Git can be used within HLRS - network. Due to existing firewall regulations, only services that have been explicitly whitelisted are allowed. Members of the University of Stuttgart can use the GitHub service operated by TIK, as its usage is only possible after accepting the IuK regulations.

If your institution also operates a GitHub service with comparable policies, please contact us so that we can whitelist the corresponding domain in the firewall if needed.

Setting Up the Git Environment

The following steps are required to set up and use a Git repository within the university network:

1. Initialize a Repository

Navigate to your project directory:

cd ~/source/example-project

Initialize a new Git repository with the default branch main:

git init -b main
2. Add Files and Create the First Commit

Add the current files to the repository:

git add .

Create the first commit with a meaningful description:

git commit -m "First commit: Project description"
3. Connect to the Remote Repository

Add the remote repository as origin:

git remote add origin git@github.tik.uni-stuttgart.de:<user>/<repository>.git
4. setup ssh connection to the Remote Repository
ssh-keygen -t ed25519 -C "github example-project" -f github-tik-example-proj

Upload the public key to the Git project via the web-interface and create a SSH-config file `~/.ssh/config` with the following content:

 HOST github.tik.uni-stuttgart.de
    HostName github.tik.uni-stuttgart.de
    User <user>
    Port 22
    IdentityFile ~/.ssh/github-tik-example-proj
5. Test the connection
ssh -vT git@github.tik.uni-stuttgart.de

The output should be something like:

Hi <user>! You've successfully authenticated, but GitHub does not provide shell access.
6. Upload Changes

Push the commits to the remote repository:

git push -u origin main

Usage Notes

  • The use of the University of Stuttgart's GitHub service requires acceptance of the IuK regulations.
  • If you wish to use a GitHub service from another institution with similar policies, please contact us.


Due to the fact that internet access is restricted within HWW-systems, you have to use a ssh tunnel to access remote repositories.