Two github accounts to push to same repo

Viewed 51

So this is a very specific use case. It would be great if any GitHub gurus can help me.

In my Linux laptop, I want to push to same GitHub repo using two different GitHub usernames.

I have setup both the SSH keys in my local machine. I have been able to configure it up until being able to switch between users when committing. This works fine and I can switch between the two configured users while committing.

However whenever I do git push I am never able to switch users and it always uses my first username.

Is there a way I can switch or select user when I push to github?

1 Answers

If all you want to do is use a different username, then you could set the username in the config right before you push each time:

$ git config user.name "other_username"
$ git config user.email "other_username"
$ git push

Notice that git uses your username when you commit, so you would have to change the username before you commit and then push as this user.

See this answer.

Related