I have two GitHub users accounts (private and work). Call them Allison and Bob.
I have a Bash script. Call it: allison_git that does:
ssh-add -D
eval $(ssh-agent -s)
git config --global credential.helper wincred
git config --global credential.useHttpPath true
git config --global user.name Allison
git config --global user.email allison@gmail.com
ssh-add ~/.ssh/allison_git_rsa
ssh -T git@github.com
If all goes well for Allison, I get:
Hi Allison! You've successfully authenticated, but GitHub does not provide shell access.
So I can switch between the users with the script that I have. Great.
However... say that user Bob is for my work and Allison is for my private and I'm working on my work repository, but forgot to switch to Bob. My commit would apply as user Allison and not Bob.
I'm not sure why (I guess because they're on the same computer?!) How can I restrict user Allison to use Bobs repository and reverse? Is my approach to all this with the Bash allison_git / bob_git causing all this?
Note: I added Bob's public key (bob_git_rsa) on his GitHub account (settings-->SSH and PGP Keys)
, and the same for Allison (allison_git_rsa). The keys are different.
You could use a conditional gitconfig directive as done here:
# All work Git repositories are in a subdirectory of ~/work.
# All other Git repositories are outside ~/work.
[includeIf "gitdir:~/work/"]
path = .gitconfig.work
The user name/email in .gitconfig.work
would be Bob's, while the default name/email would be Alice for any other repository outside ~/.work
.
Note that git config --global credential.helper wincred
applies only for HTTPS URL, and is not used if you are authenticated with SSH.