Quick tip: how I manage multiple Git(hub) accounts & SSH pulls on OS X El Capitan
Aditya M (hello@adityamenon.co)

Quick tip: how I manage multiple Git(hub) accounts & SSH pulls on OS X El Capitan

  1. I have > 1 Github accounts: work, play, more_work etc.
  2. I want to be able to easily run `git pull` & `git push` from repositories on each account without having specify login credentials each time.
  3. Git SSH works, but the work key overrides the play key or vice versa.

I ended up having to tell Git which Private key to use each time to sign in to Github while pushing, with `ssh -i /path/to/key`, which is annoying to do for each account.

What do?

I located the SSH private key for your non-primary Github/whatever Git hosting account (comment if you have questions here!). This was easy for me because I had generated the keys and uploaded them to Github.

Then I setup a Terminal Profile in OS X. It looks like this:

1. Open up Terminal > Preferences... from the Menu.

2. Hit the + button to create a new Profile.

3. Go to Shell, and in the Run Command field paste in the following:

    export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_work.work"; cd ~/work/myproject

4. NOTE: the path is to the Private key not the Public key (! the *.pub file).

5. NOTE: you can actually append more stuff to the command after the ; adding as many commands as you like, but this will slow down your terminal starting experience.

6. NOTE: make sure the Run inside shell checkbox is ticked!

That's it! I can now open new tabs or windows with that profile, and just run `git pull` & `git push` to my heart's content .

This saved me from having to set the GIT_SSH_COMMAND environment variable or specify the  the private key with `git -i` flag each time.

PS: Instructions in this post were tested on OS X El Capitan 10.11.3 and Git version 2.5.4.

PPS: I can feel some sysadmins cringing at this method already. Please comment with your suggestions if you think this can be done better (with the reasons) :-)

To view or add a comment, sign in

More articles by Aditya MP

Explore content categories