Skip to content

Instantly share code, notes, and snippets.

@anabellaspinelli
Last active June 18, 2017 03:38
Show Gist options
  • Save anabellaspinelli/c465e4f5d83a4dc59c85 to your computer and use it in GitHub Desktop.
Save anabellaspinelli/c465e4f5d83a4dc59c85 to your computer and use it in GitHub Desktop.
Using 2 (or more) GitHub accounts on the same machine

Setting up another GitHub account

And then adding remotes and users accordingly
  1. First, create a new SSH key and link it to the new GitHub account you want to use. When prompted to choose the file, change it to another different than the default one. Remember to give a full path, otherwise it will be created on the current directory. This is the process for this step: https://help.github.com/articles/generating-ssh-keys/

  2. Add the hosts on /Users/dev/.ssh/config. If the file doesn't exist, create it. Example:

     Host github.com-anabellaspinelli
         HostName github.com
         User git
         IdentityFile /Users/dev/.ssh/id_rsa_personal
         IdentitiesOnly yes
     Host github.com-anabella-spinelli-company
         HostName github.com
         User git
         IdentityFile /Users/dev/.ssh/id_rsa
         IdentitiesOnly yes
    
  3. Clone/initialize the repo.

  4. Add/change the remote to the repo using the corresponding host.

  • For cloned repositories:

      git remote set-url origin [email protected]:anabellaspinelli/mockiavelli.git
    
  • For new repositories (originally initialized locally):

      git remote add origin [email protected]:anabellaspinelli/mockiavelli.git
    
  • The format is:

      {user}@{host}:{GitHubUser}/{repository}.git
    
  1. The most important part, tell the repo who you are, set up user.name and user.email for that repo. Example:

     git config --local user.name "Anabella Spinelli"
     git config --local user.email "[email protected]"
    

Now for every new repo that you clone you must specify which account on your git config you will use and set up a valid username and email for it (steps 4 and 5).

@andres-cianio
Copy link

Worked like a charm! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment