nerd space
  1. Git config Hack
    1. Background
    2. The main Hack
    3. Other hacks
13 May 2022

Git config Hack


I have two github users for different things, one as a data hoarder and the other one for my projects. That being the case I have one github config but now when I am pushing to the other github repo the username for my main github account is seen on the other and I am genuinely not happy about that.

The main Hack

Here comes the hack I found on stackoverflow

  • main gitconfig at home directory.
  path = ~/.iAmG-r00t.gitconfig

[includeIf "gitdir:~/Documents/github/sventek-s/"]
  path = ~/.sventek.gitconfig

  editor = /usr/bin/vim
  excludesfile = /home/null/.gitignore

# --- .iAmG-r00t.gitconfig --- #
# default gitconfig
  name = iAmG-r00t
  email = [REDACTED]

# --- .sventek.gitconfig --- #
# sventek's github config
  name = sventek-s
  email = [REDACTED]

gitdir is case-sensitive and gitdir/i is case-insensitive.

BOOM, no more mixed users in commits.

Other hacks

I don’t remember where I found this hack, but basically I use SSH keys to manage my git stuff on my pc. While having two accounts I had to find a way to specify what repo’s use which key and what not.

SSH config file.

# first user iAmG-r00t
     User git
     PreferredAuthentications publickey
     IdentityFile ~/path/to/ssh/private-key

# second user sventek
     User git
     PreferredAuthentications publickey
     IdentityFile ~/path/to/ssh/private-key

Then once after cloning or creating a repo for sventek, you need to change the remote url origin.


  • Original from github will look like this;
  • Edited;

command to change remote url origin: git remote set-url origin

confirm if change has been made: git remote show origin

[UPDATE] Added a global gitignore file.