opinionated git management

a friend mentioned needing a way to configure an additional git identify for their new job. i have been in this situation before when maintaining accounts on GitHub and GitLab tiers, and know how much it can be a nightmare.

i tried a couple different ways over the years and formed an opinion as to what is overall easiest to extend. you might find it useful if you’re in the same situation

the opinionated .gitconfig solution

what i recommend is make a folder for the user and clone repos under it, mkdir ~/othergitconfig

in a unix user’s current default git config you would add

~/.gitconfig
[includeIf "gitdir:~/othergitconfig/"]
    path = ~/othergitconfig/.othergitconfig

for the next step, something like this gets you started. configure it to match the account you plan to make commits as.

~/othergitconfig/.othergitconfig
[user]
    name = "name for commits"
    email = "email for commits"

this allows me to keep my current directories setup as-is, and when im working as that account id git clone and work under the code inside the same ~/othergitconfig!

here is a sequence of commands you can verify if it works on your machine with:

export TEST_REPO=~/othergitconfig/my-test-repo
mkdir $TEST_REPO && cd $TEST_REPO
git init
git config --list