2

I have been struggling for several hours across multiple days on this. I am trying to setup my Ubuntu 20.04.4 LTS machine.

I realize there are other similar posts/questions, but none have been able to help resolve my issue.

I have tried following the following walk-throughs:

https://www.freecodecamp.org/news/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca/

https://www.freecodecamp.org/news/how-to-handle-multiple-git-configurations-in-one-machine/

https://blog.gitguardian.com/8-easy-steps-to-set-up-multiple-git-accounts/

https://medium.com/big-data-processing/multiple-git-accounts-on-same-computer-27199e7ba1f2

I checked these other questions:

Why .gitconfig [includeIf] does not work?

Multiple GitHub Accounts & SSH Config

How to configure multiple github accounts on your computer?

I fear I may be having issues with some syntax somewhere.

To start, I have two ssh keys generated and already added to their respective Github accounts. My ./ssh/config is as follows:

#first account
Host github.com-firstUserName
    HostName github.com
    User git
    IdentityFile ~/.ssh/firstKey

#second account
Host github.com-secondUserName
    HostName github.com
    User git
    IdentityFile ~/.ssh/secondKey

My directories are laid out as follows:

/home/pcUserName/
    |_.gitconfig
    |_personal/
        |_.gitconfig-pers
        |_personal-repo1/
        |_personal-repo2/
    |_professional/
        |_.gitconfig-dev
        |_professional-repo1/
        |_professional-repo2/

My global gitconfig contains the following:

[includeIf "gitdir:~/repos/personal/"]
path = ~/.gitconfig.pers

[includeIf "gitdir:~/repos/professional/"]
path = ~/.gitconfig.dev

And I have the following local gitconfigs:

# ~/personal/.gitconfig.pers
[user]
email = "first@user.com"
name = "firstUserName"
[github]
user = "firstUserName"
[core]
sshCommand = "ssh -i ~/.ssh/firstKey"

and

# ~/professional/.gitconfig.dev
[user]
email = "second@user.com"
name = "secondUserName"
[github]
user = "secondUserName"
[core]
sshCommand = "ssh -i ~/.ssh/secondKey"

I get a successful test as follows:

ssh -T git@github.com-firstUserName
Hi firstUserName! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@github.com-secondUserName
Hi secondUserName! You've successfully authenticated, but GitHub does not provide shell access.

But then I try

cd repos/professional/
mkdir test-repo
cd test-repo
git init
git config -l
    filter.lfs.required=true
    filter.lfs.clean=git-lfs clean -- %f
    filter.lfs.smudge=git-lfs smudge -- %f
    filter.lfs.process=git-lfs filter-process
    init.defaultbranch=main
    color.ui=auto
    core.editor=code --wait
    includeif.gitdir:~/repos/personal/.path=~/.gitconfig.pers
    includeif.gitdir:~/repos/professional/.path=~/.gitconfig.dev
    core.excludesfile=~/.gitignore
    core.repositoryformatversion=0
    core.filemode=true
    core.bare=false
    core.logallrefupdates=true

I would expect to see user.name and user.email being set here, right? I have tried looking over man git and https://git-scm.com/docs/git-config but at this point, I am at a loss. Any help would be greatly appreciated.

  • 1
    Both includes in the global `.gitconfig` use wrong paths. – phd Apr 10 '22 at 18:29
  • Can you elaborate? I cannot find what the exact syntax should be. – ObsidianZed Apr 10 '22 at 18:49
  • Should they be the full `path = ~/repos/personal/.gitconfig.pers` or would something like `path = ../gitconfig.pers` work? – ObsidianZed Apr 10 '22 at 18:58
  • @ObsidianZed : you seem yo use `~` as if it meant "the current working directory", but `~` is a shortcut for "my home directory". Were you aware of this point ? – LeGEC Apr 10 '22 at 19:11
  • Why not just copy a perso `.gitconfig` into your perso project and keep pro on the global one ? I do like this as several open source project have specific needs (email review, signed commit etc.) so at the end several needs specific config – Ôrel Apr 10 '22 at 19:33
  • 1
    @ObsidianZed In the global `.gitconfig` you better use full paths: `path = ~/personal/.gitconfig-pers` and `path = ~/professional/.gitconfig-dev`. Also please note you use dots in config but minus in filenames: `.gitconfig.pers` vs `.gitconfig-pers`. Please be careful with paths and filenames. – phd Apr 10 '22 at 20:11
  • 1
    @phd Yes thank you! I thought I was using `~` correctly at some point and even had the full paths, but I felt like I was going crazy and just started trying all sorts of different syntax. I finally got that I was mixing `.` and `-` and went back and started again and it is now working! Thanks for the help! I probably should have just stepped away and came back with some fresh eyes. – ObsidianZed Apr 10 '22 at 23:56
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Apr 11 '22 at 09:40

0 Answers0