- 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: Difference between revisions

From HLRS Platforms
Jump to navigationJump to search
(→‎Usage on HWW/HLRS platforms: wie setzen wir das TiK git auf)
Line 83: Line 83:
== Usage on HWW/HLRS platforms ==
== Usage on HWW/HLRS platforms ==


In order to use Git on our platforms Hazelhen, Laki and Kabuki, load the corresponding module
In order to use Git on our platforms vulcan, hunter, ...  load the corresponding module
{{Command | command =
{{Command | command =
module load tools/git
module load tools/git
}}
}}


=== Using Git provided by University of Stuttgart (TiK) ===


<font color=red>Due to the fact that internet access is restricted within HWW-systems, you have to use a [[Secure_Shell_ssh#Git | ssh tunnel]] to access remote repositories.</font color>
==== 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 [https://github.tik.uni-stuttgart.de/ 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:
<code>cd ~/source/example-project</code>
Initialize a new Git repository with the default branch <code>main</code>:
<code>git init -b main</code>
 
===== 2. Add Files and Create the First Commit =====
Add the current files to the repository:
<code>git add .</code>
Create the first commit with a meaningful description:
<code>git commit -m "First commit: Project description"</code>
 
===== 3. Connect to the Remote Repository =====
Add the remote repository as <code>origin</code>:
<code>git remote add origin git@github.tik.uni-stuttgart.de:<user>/<repository>.git</code>
 
===== 4. setup ssh connection to the Remote Repository =====
<code>ssh-keygen -t ed25519 -C "github example-project" -f github-tik-example-proj</code>
<code>Upload the public key to the Git project via the web-interface and create a SSH-config file `~/.ssh/config` with the following content:</code>
  <code>HOST github.tik.uni-stuttgart.de
    HostName github.tik.uni-stuttgart.de
    User <user>
    Port 22
    IdentityFile ~/.ssh/github-tik-example-proj</code>
 
===== 5. Test the connection =====
<code>ssh -vT git@github.tik.uni-stuttgart.de</code>
The output should be something like:
<code>Hi <user>! You've successfully authenticated, but GitHub does not provide shell access.</code>
 
===== 6. Upload Changes =====
Push the commits to the remote repository:
<code>git push -u origin main</code>
 
==== 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.
 
 
<font color="red">Due to the fact that internet access is restricted within HWW-systems, you have to use a [[Secure_Shell_ssh#Git | ssh tunnel]] to access remote repositories.</font>


[[Category:Revision Control]]
[[Category:Revision Control]]

Revision as of 16:33, 11 February 2025

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


Git and Subversion (SVN)

For Git a very nice plugin for subversion exists. It allows to check out and commit changes to a remote svn directory while holding a local git repository.

You can create a svn directory tracked via git with

git svn init [options] URL


To check out the svn director and rebase the currently checked out git branch via

git svn fetch
git svn rebase


To commit changes from a git branch to the svn repository use

git svn dcommit


Have a look on the help system for the svn command as a lot of options exist:

git help svn


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.