location: Diff for "Git"

Institute of Mathematics - PublicMathWiki:

Differences between revisions 3 and 45 (spanning 42 versions)
Revision 3 as of 2013-07-23 12:58:49
Size: 963
Editor: sericm
Comment:
Revision 45 as of 2023-09-02 12:26:59
Size: 6571
Editor: crose
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
|| Server Info || `git.math.uzh.ch` || || Server Info || https://git.math.uzh.ch ||
Line 4: Line 4:
|| Git push/pull access || mainly via SSH over `git@git.math.uzh.ch` || || Git push/pull access || mainly via SSH over `git@git.math.uzh.ch` - ```do not forget to upload your public ssh key``` ||
|| Cheat sheet || [[http://www.git-tower.com/blog/git-for-subversion-users-cheat-sheet/|GIT for SVN users]] ||


<<TableOfContents>>
Line 7: Line 11:
You need the following software:
 * [[http://git-scm.com/|Git]]
 * An SSH keypair.

= Create/Request an account =

=== For Members of I-MATH ===
 * You don't need to request a special account for Gitlab.

=== For Non-Members of I-MATH ===
If you wan't to collaborate with a project which is hosted on `git.math.uzh.ch`, you need to request a special Gitlab account. It's best if you write an email with a request to 'support AT math.uzh.ch'.

You will then receive an email for validation and first-time login.

=== After the first-time login ===

 * [[http://git-scm.com/|Git]] installed (already done on IMATH server).

= SSH Keys =

To work with private GIT repos or to commit files, it's necessary to identify yourself. This is done via SSH Keys. Do this on all devices which you like to use with the GIT server (and in your I-MATH thinlinc session if you use it).

 * Setup SSH keys (per device) - [[https://help.github.com/articles/generating-ssh-keys/|HowTo create private/public ssh keys]]
 * Linux: On your device/session, push the keys to your ssh-agent {{{
eval "$(ssh-agent -s)"
}}}
 * Do a test:
 
  * Via ssh: `ssh -T git@git.math.uzh.ch` (do '''not''' replace `git` with your username, use '''git@git.math.uzh.ch''' as written).
  * By cloning a repo.

= Git account =

== For members of I-MATH ==

 * Use your regular 'I-MATH' account to login.
 * https://git.math.uzh.ch/users/sign_in > Tab 'MATH User'

== For members of UZH (not I-MATH) ==

 * Open your I-MATH account (based on your UZH Webpass account) under [[https://math.uzh.ch/account]]
 * https://git.math.uzh.ch/users/sign_in > Tab 'MATH User'

== For non UZH persons ==

If you like to collaborate on a project which is hosted on [[https://git.math.uzh.ch]], you have to request a git.math.uzh.ch account.

 * Best is to ask a project member affiliated with I-MATH to request the account via [[https://math.uzh.ch/support]].
 * You will then receive an email for validation and first-time login.
 * https://git.math.uzh.ch/users/sign_in > Tab 'Standard'

== After the first-time login ==
Line 23: Line 49:

 * You need to provide your public SSH key. This can easily be done on the Gitlab web-interface.
 * '''Recommended''': You need to provide your public SSH key. This can easily be done on the Gitlab web-interface.

= Working with Git =

{{{
git COMMAND git@git.math.uzh.ch/<username>/<projectname>
}}}

= Managing your Projects with Gitlab =
Gitlab has quite extensive managing capabilities.

 * You can, among other things,
   * Crate/fork/rename/remove projects
   * Create/delete/join Teams
   * Assign members with roles to projects
   * Create/Assign issues
   * Have a wiki for a project

 * The gitlab user documentation is found on `https://git.math.uzh.ch/help`.

= GIT Best Practice =

== New project from scratch ==
 * Create a new project via the webinterface.
{{attachment:git.project.png}}
 * You'll see a summary with the next steps:
{{{
Git global setup
----------------
git config --global user.name "First Lastname"
git config --global user.email "email@math.uzh.ch"

Create a new repository
-----------------------
mkdir <local projektdir>
cd <local projektdir>
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@git.math.uzh.ch:<project>.git
git push -u origin master

Push an existing Git repository
-------------------------------
cd existing_git_repo
git remote add origin git@git.math.uzh.ch:<project>.git
git push -u origin master
}}}

== GIT daily use ==

=== Local: Add new files to existing repo ===
{{{
git add <file>
}}}

=== Local: Work on your files ===
 * Commit changes locally
{{{
git commit -a
}}}
 * Or at IMATH you can use `git-commit`, which will in every file replace `$Id$` by User/timestamp:
{{{
git-commit
}}}

 * Commit changes remote
{{{
git push
}}}

=== Local: clone an existing repo to start working on it ===
{{{
git clone git@git.math.uzh.ch:<project>.git
}}}

== Purged Remote branches still shown locally ==

 * See: http://stackoverflow.com/a/17320081/1167442
{{{
$ git remote update --prune
}}}

== Purge a file completely from all commits & branches ==

 * This is not how GIT should be used!
 * ONLY, ONLY, ONLY do this if it is absolutly necessary!
 * There might be side effects, you're on your own!
 * Source: https://github.com/nachoparker/git-forget-blob
{{{
$ cd <root of your repo>
$ git-forget-file.sh <path to file>/<file>
}}}

== Overwrite local branch with remote ==

 * https://phoenixnap.com/kb/git-overwrite-local-branch-with-remote

== Visually show commit history ==

 * `gitg`
 * Use the git.math.uzh.ch webinterface

== Search the commit which breaks something ==

 * Based on binary search.
 * Give a good and a bad commit.
 * The `git bisect ...` command always looks for the commit in the middle. Do a check of such a commit and decide to continue the search in the lower or upper half.
 * https://git-scm.com/docs/git-bisect

= FAQ =


== Change Repo: http > ssh ==

{{{

# Status Quo
$ git remote -v show
origin https://systemvcs.math.uzh.ch/it/typo3-docker.git (fetch)
origin https://systemvcs.math.uzh.ch/it/typo3-docker.git (push)

# Remove Origin
$ git remote rm origin

# Set SSH Version
$ git remote add origin git@systemvcs.math.uzh.ch:it/typo3-docker.git


# Status Quo
git remote -v show
origin git@systemvcs.math.uzh.ch:it/typo3-docker.git (fetch)
origin git@systemvcs.math.uzh.ch:it/typo3-docker.git (push)

# Try a git pull:
$ git pull

# If you receive: There is no tracking information for the current branch. ... try:
$ git branch --set-upstream-to=origin/main main
}}}

'''Attention''': if you change to SSH and

 * You use SSH public key (stored on GIT server),
 * You're logged in on a remote server by ssh and you're using a different user ID than the one where the public key on the git server belongs to,

than you should forward your SSH-Agent! E.g. '''ssh root@host -A'''

== Pipeline failed notification ==

 * Maintainer receives all pipeline errors per mail by default
   {{attachment:screen_gitlab_error.png}}
 * Others can subscribe to it on the main site of a project:
   {{attachment:setting_notifaction.png}}

== Windows Change Saved Git Password ==

 * Open "Credential Manager" (German: "Anmeldeinformationsverwaltung")
   {{attachment:01_credential_manager.png}}
 * Choose "Windows Credentials" (German: "Windows-Anmeldeinformationen") and remove all saved credentials for Git.
   {{attachment:02_windows_credentials.png}}
 * Use git as usual, you will be asked to enter your password

Server

Server Info

https://git.math.uzh.ch

Software

Gitlab

Git push/pull access

mainly via SSH over git@git.math.uzh.ch - do not forget to upload your public ssh key

Cheat sheet

GIT for SVN users

Prerequisites

  • Git installed (already done on IMATH server).

SSH Keys

To work with private GIT repos or to commit files, it's necessary to identify yourself. This is done via SSH Keys. Do this on all devices which you like to use with the GIT server (and in your I-MATH thinlinc session if you use it).

  • Setup SSH keys (per device) - HowTo create private/public ssh keys

  • Linux: On your device/session, push the keys to your ssh-agent

    eval "$(ssh-agent -s)"
  • Do a test:
    • Via ssh: ssh -T git@git.math.uzh.ch (do not replace git with your username, use git@git.math.uzh.ch as written).

    • By cloning a repo.

Git account

For members of I-MATH

For members of UZH (not I-MATH)

For non UZH persons

If you like to collaborate on a project which is hosted on https://git.math.uzh.ch, you have to request a git.math.uzh.ch account.

After the first-time login

  • If you requested an "external" account, you will be asked to change your initial password.
  • Recommended: You need to provide your public SSH key. This can easily be done on the Gitlab web-interface.

Working with Git

git COMMAND git@git.math.uzh.ch/<username>/<projectname>

Managing your Projects with Gitlab

Gitlab has quite extensive managing capabilities.

  • You can, among other things,
    • Crate/fork/rename/remove projects
    • Create/delete/join Teams
    • Assign members with roles to projects
    • Create/Assign issues
    • Have a wiki for a project
  • The gitlab user documentation is found on https://git.math.uzh.ch/help.

GIT Best Practice

New project from scratch

  • Create a new project via the webinterface.

git.project.png

  • You'll see a summary with the next steps:

Git global setup
----------------
git config --global user.name "First Lastname"
git config --global user.email "email@math.uzh.ch"

Create a new repository
-----------------------
mkdir <local projektdir>
cd <local projektdir>
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@git.math.uzh.ch:<project>.git
git push -u origin master

Push an existing Git repository
-------------------------------
cd existing_git_repo
git remote add origin git@git.math.uzh.ch:<project>.git
git push -u origin master

GIT daily use

Local: Add new files to existing repo

git add <file>

Local: Work on your files

  • Commit changes locally

git commit -a
  • Or at IMATH you can use git-commit, which will in every file replace $Id$ by User/timestamp:

git-commit
  • Commit changes remote

git push

Local: clone an existing repo to start working on it

git clone git@git.math.uzh.ch:<project>.git

Purged Remote branches still shown locally

$ git remote update --prune

Purge a file completely from all commits & branches

$ cd <root of your repo>
$ git-forget-file.sh <path to file>/<file>

Overwrite local branch with remote

Visually show commit history

  • gitg

  • Use the git.math.uzh.ch webinterface

Search the commit which breaks something

  • Based on binary search.
  • Give a good and a bad commit.
  • The git bisect ... command always looks for the commit in the middle. Do a check of such a commit and decide to continue the search in the lower or upper half.

  • https://git-scm.com/docs/git-bisect

FAQ

Change Repo: http > ssh

# Status Quo
$ git remote -v show
origin  https://systemvcs.math.uzh.ch/it/typo3-docker.git (fetch)
origin  https://systemvcs.math.uzh.ch/it/typo3-docker.git (push)

# Remove Origin
$ git remote rm origin

# Set SSH Version
$ git remote add origin git@systemvcs.math.uzh.ch:it/typo3-docker.git


# Status Quo
git remote -v show
origin  git@systemvcs.math.uzh.ch:it/typo3-docker.git (fetch)
origin  git@systemvcs.math.uzh.ch:it/typo3-docker.git (push)

# Try a git pull:
$ git pull

# If you receive: There is no tracking information for the current branch. ... try:
$ git branch --set-upstream-to=origin/main main

Attention: if you change to SSH and

  • You use SSH public key (stored on GIT server),
  • You're logged in on a remote server by ssh and you're using a different user ID than the one where the public key on the git server belongs to,

than you should forward your SSH-Agent! E.g. ssh root@host -A

Pipeline failed notification

  • Maintainer receives all pipeline errors per mail by default
    • screen_gitlab_error.png

  • Others can subscribe to it on the main site of a project:
    • setting_notifaction.png

Windows Change Saved Git Password

  • Open "Credential Manager" (German: "Anmeldeinformationsverwaltung")
    • 01_credential_manager.png

  • Choose "Windows Credentials" (German: "Windows-Anmeldeinformationen") and remove all saved credentials for Git.
    • 02_windows_credentials.png

  • Use git as usual, you will be asked to enter your password

PublicMathWiki: Git (last edited 2023-10-22 16:01:43 by crose)