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.