Managing multiple github accounts

When you are dealing with multiple github accounts you have to be careful of two things:

  • Having proper rights to pull from git
  • Having proper rights to push to git

It may seem as to the solution to both the problems should be the same, but they are slightly different. Lets look at both the points :

Having proper rights to pull from git

When you are dealing with multiple accounts, there is this nice post which gives the instructions as to how to go about it.

Here the basic essence of the whole procedure is that one has to be careful as to which SSH key is being associated with the github account. This is being precisely targeted in the above indicated post.

Having proper rights to push to git

Now the first question which comes to mind is, “Why isn’t the last setup sufficient for resolving this?".

That would have been the case (not requiring further complications) if only one user can work on a single SSH key. You can have a single SSH key being used by different user-names on different github project. Hence the question arises, “Which is the correct user-name for the current commit push?”

Thus, in conclusion, one should set up local config setting for each project using,

git config user.email "accountname@domain.com"
git config user.name "username"

You can as well use the above commands with the global flag to set it common for all the projects as follows

git config --global user.email "accountname@domain.com"
git config --global user.name "username"

This will set the credentials for user.email and user.name as a backup option when the local setting are not present. However I would discourage the use of the global flag. A logical thought experiment is below:

Lets consider you start a new project with a username which is different from what is set using the global flag. Now in case you forget to setup the local credentials and push your changes then the changes are being pushed with a undesirable username and email.

If on the other hand, the global user.email and user.name settings are not present, git throws error during pushing that you have not setup the local settings and thus cannot push, which will remind you to setup the credentials which you want to push the changes by.

License

Copyright 2017 Parth Thaker .

Released under the MIT license.

Avatar
Parth K. Thaker
Ph.D. Student

My research interests are mainly in problems at the intersection of Graph Theory and Optimization.