From 386c98b1a528823644555772eaa70da780e71b69 Mon Sep 17 00:00:00 2001
From: MB <michael.blaschek@univie.ac.at>
Date: Fri, 30 Apr 2021 17:44:09 +0200
Subject: [PATCH] add git sync tool

---
 Git/README.md      | 27 +++++++++++++++++++++++++++
 Git/git-repos-sync | 10 ++++++++++
 2 files changed, 37 insertions(+)

diff --git a/Git/README.md b/Git/README.md
index e6cbd77..ad06984 100644
--- a/Git/README.md
+++ b/Git/README.md
@@ -3,6 +3,33 @@ There is a lot of ways how to use git and sometimes a working solution can be ve
 
 [[_TOC_]]
 
+## HowTo add a specif ssh-key for your git account
+Sometimes it might be useful to have different ssh-keys per project or have a special ssh-key just for github/gitlab.
+
+Steps:
+1. Generate a `ssh-keygen`
+2. Add ssh-key to GitHub or GitLab account under settings
+3. Write a `~/.ssh/config` file with a content like this
+
+```
+Host github.com
+	HostName github.com
+	User git
+	IdentityFile ~/.ssh/id_rsa_for_git
+
+Host gitlab.com
+	HostName gitlab.com
+	User git
+	IdentityFile ~/.ssh/id_rsa_for_gitlab
+```
+Make sure that you adjust the `Hostname` accordingly and be sure that you use ssh in your git repo:
+```bash
+$ git remote -v
+origin  git@github.com:USER/repo.git (fetch)
+origin  git@github.com:USER/repo.git (push)
+```
+show no `https` in the urls.
+
 
 ## HowTo Sync a GitHub and a GitLab repository
 It is easy to import a GitHub repo into GitLab and the otherway around. However, if you want to make sure you can have both repos at the same state, you need to syncronize them.
diff --git a/Git/git-repos-sync b/Git/git-repos-sync
index 1969510..c1381ee 100755
--- a/Git/git-repos-sync
+++ b/Git/git-repos-sync
@@ -9,6 +9,16 @@ if [ "$#" -ne 3 ]; then
     exit 1
 fi
 
+# Check if you are at root level (fails if not)
+if ! git rev-parse --show-toplevel; then
+	>&2 echo "Git repo found"
+	if [ $PWD == $(git rev-parse --show-toplevel) ]; then
+		echo "Not at root of local repo"
+		echo $(git rev-parse --show-toplevel)
+		exit 1
+	fi
+fi
+
 if [ ! -d ".git" ]; then
 	echo "Git repo for syncronization is not found, creating one..."
 	git init
-- 
GitLab