As a freelance developer I get to work with different clients and contractors and it’s common to find that they use different repository hosting services; Github, Codebase, Bitbucket, etc. Today I’ll share my experience configuring Git in order to work with multiple repository hosting providers.
Besides, I had a pretty bad time with errors like “Permission denied (publickey).” and “Could not open a connection to your authentication agent.“.
The default identity should be the one you use for your personal projects or work or just the one you use the most. There are ways to configure it and almost every provider has the proper instructions in how to set it up (Github, Bitbucket, Codebase).
As you can see they’re almost the same and that experience will come in handy in just a second.
Now we need new identities because sometimes we’re given a new email address in order to work with that new client or just need to create a new identity in order to sync with a new repository hosting provider.
Step 0: Change your config name and email (if necessary)
You gotta keep this always in mind when making commits and pushing to foreign repositories (not the default one) and change them back after pushing to remotes.
$ git config --global user.name "Your Name"
$ git config --global user.email firstname.lastname@example.org
Step 1: Generate a new SSH key
$ ssh-keygen -t rsa -C "email@example.com"
# Creates a new key
Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [selected_name]
# selected_name should be one that clearly identifies this new identidy
# I use the naming rule [provider]_rsa
# for example: github_rsa, bitbucket_rsa, codebase_rsa
Step 2: Create or modify the SSH config file
# Create a new config file if necessary
$ touch ~/.ssh/config
Modify the file using the following format
Given the files I named above, the file looks like this
Save it and that’s it. It should work now as expected for those different repository hosting providers you configured (or at least that’s what’s worked for me).