Issue
So I needed to add my personal GitHub account to my office laptop in which I was already using my work github account. So I created a separate ssh key and stored that into a separate file. I added that newly created ssh to my personal github account.
Then I added a config file like this:
Work
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
I then created a PRIVATE new repository in personal git repository and cloned it like the following so that it will use personal ssh token:
git clone [email protected]:prajatpadhi/udemy-react-maximillian.git
I then made some commits and pushed. But I was surprised to see that the commit's author was my work's userid because I had forgotten to change the username and email of my local repository.
But shouldn't in such a case there should be an authorization error as the repository was private in the personal git hub account. How did GitHub allowed access?
My personal userid is lets say pp and work's pp1. How can pp1 be allowed to push a commit to pp's private repository?
Solution
But shouldn't in such a case there should be an authorization error as the repository was private in the personal git hub account.
How did GitHub allowed access?
No, commit authorship has nothing to do with authentication/access.
It is better to use a conditional includeIf.<condition>.path
global setting in order to set user.name
/user.email
depending on the project folder you are in.
That way, you don't forget to set the right name/email, and your created commits are done with the right author.
Answered By - VonC Answer Checked By - Clifford M. (WPSolving Volunteer)