commit 8902e8b9767f48d11c57df4fe2213b45eca6b012
parent 22a8769ff680f58aa878f7f8e7e3eb39cb8ae026
Author: pyratebeard <root@pyratebeard.net>
Date: Sun, 13 Apr 2025 17:23:39 +0100
a_tale_of_two_gits
Diffstat:
1 file changed, 49 insertions(+), 0 deletions(-)
diff --git a/entry/a_tale_of_two_gits.md b/entry/a_tale_of_two_gits.md
@@ -0,0 +1,49 @@
+---
+title: a_tale_of_two_gits
+keywords: [git, linux, programming, ssh, tips]
+...
+
+When working on personal and "work" code repositories on my PC I prefer to use different Git `[user]` settings depending on the repo, using my meatspace handle for work. I have found the easiest way to achieve this is setting a rule in my Git config to use an alternative config based on the directory.
+
+
+This is my main Git config
+```
+[init]
+ defaultbranch = main
+[user]
+ email = root@pyratebeard.net
+ name = pyratebeard
+ username = pyratebeard
+ signingkey = 0xC7877C715113A16D
+ useconfigonly = true
+[includeif "gitdir:/home/pyratebeard/src/suit/"]
+ path = ~/.config/git/config.suit
+```
+
+The important section is the `includeif` at the end. This tells Git that if the repo is located under the _$HOME/src/suit/_ directory then pull in the settings from another config file.
+
+This is _config.suit_
+```
+[user]
+ email = captain@mail.com
+ name = captain beard
+ username = capn
+ signingkey = 0x766A144AC7
+ useconfigonly = true
+[url "git@gitlab.com-suit"]
+ insteadof = git@gitlab.com
+```
+
+The file has my alternative `[user]` settings as well as an override for the Gitlab SSH settings. I then have two Gitlab hosts configured in my SSH config so when I'm pushing work code it uses my work SSH key.
+```
+Host gitlab.com
+ HostName gitlab.com
+ User git
+ IdentityFile ~/.ssh/pyratebeard_gpg_ssh-gitlab.pub
+
+Host gitlab.com-suit
+ HostName gitlab.com
+ User git
+ IdentityFile ~/.ssh/suit_gpg_ssh.pub
+```
+