0

I have 2 different Github accounts. And I've setup 2 different SSH keys. Registered both keys on Github with the correct account and created a git config file that should use the right credentials for working with the remote repository (ie use my personal account for personal work and work account for remote work). This is what my git config file looks like:

Host personal.github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes

Host work.github.com
HostName github.com
PreferredAuthentications publickey
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes

It works, I can clone and push projects.

The problem:

Let's say i create a new remote repo in my work account. When I clone the project on my local machine I use: git clone [email protected]:[username]/my-plan.git

Then make some changes, commit them and push it back to the remote repo. It works, but instead of showing my work account credentials under "Contributors" it actually shows my personal account.

If I run git remote -v I get:

origin  [email protected]:[username]/my-plan.git (fetch)
origin  [email protected]:[username]/my-plan.git (push)

I dont understand why is this happening when the associated SSH key is connected to my work account and not my personal account. What I need to do to make sure that every time i push the project back, its from my work account and not personal one?

1 Answer 1

1

I think the problem is not with your SSH keys, github differs user that "pushed" commit and one who "committed" changes.

You can use your browser to navigate to:

https://api.github.com/repos/[username]/[repo]/commits

Each commit will have

  "author": {
    "name": "<author1>",
    "email": "<email1>",
    "date": "2019-09-17T12:56:43Z"
  },
  "committer": {
    "name": "<author2>",
    "email": "<email2>",
    "date": "2019-09-17T12:56:43Z"
  },

If emails are different - that's the problem and you should configure your git for current project locally (git config user.email "<your email for this repo>").

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.