Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BrianCurliss/b9b990ade4bf5f8ad5a24f82457bd9b1 to your computer and use it in GitHub Desktop.

Select an option

Save BrianCurliss/b9b990ade4bf5f8ad5a24f82457bd9b1 to your computer and use it in GitHub Desktop.

Revisions

  1. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    >
    > Replace `user1` or `user2` with your GitHub usernames/identification-handlers
    #### 4. Go ahead to git clone the respective repository
    #### 4. Go ahead to git clone your respective repository
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
  2. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    The only way I've succeeded so far is to employ SSH.

    Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH `config` file in a `.ssh` directory. The `config` file is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account, and all your SSH keys generated are saved into `.ssh` directory by default. You can navigate to it by running `cd ~/.ssh` within your terminal, open the `config` file with any editor, and by default it should look something like this:
    Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH `config` file in a `.ssh` directory. The `config` file is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account, and all your SSH keys generated are saved into `.ssh` directory by default. You can navigate to it by running `cd ~/.ssh` within your terminal, open the `config` file with any editor, and it should look something like this:

    >```bash
    >Host *
  3. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    #### 2. Register your keys to the respective GitHub accounts.
    * Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    * Follow these [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) to do so.
    #### 3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:
  4. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    The only way I've succeeded so far is to employ SSH.

    Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH `config` file in a `.ssh` directory and this is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account. You can navigate to it by running `cd ~/.ssh` within your terminal, open the `config` file with any editor, and by default it should look something like this:
    Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH `config` file in a `.ssh` directory. The `config` file is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account, and all your SSH keys generated are saved into `.ssh` directory by default. You can navigate to it by running `cd ~/.ssh` within your terminal, open the `config` file with any editor, and by default it should look something like this:

    >```bash
    >Host *
  5. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    #### 5. Configure your git identity:
    * Open up local git config using `git config --local -e`and add:
    * Open up local git config using `git config --local -e` and add:
    >```bash
    >[user]
    @@ -62,7 +62,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    #### 6. Ensure your remote url is in the right format e.g: `[email protected]:user1/your-repo-name.git your-repo-name_user1`
    * You either run `git remote set-url origin [email protected]:user1/your-repo-name.git your-repo-name_user1`
    * or amend your remote ssh-url in your local git config file:
    * Or amend your remote ssh-url in your local git config file:
    > ```bash
    > [remote "origin"]
    > url = [email protected]:user1/your-repo-name.git
  6. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    >
    > Replace `user1` or `user2` with your GitHub usernames/identification-handlers
    #### 4. Go ahead to git clone the respective GitHub account
    #### 4. Go ahead to git clone the respective repository
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
  7. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -75,3 +75,5 @@ Now you can git actions (pull/push/fetch...etc) all you like!
    * [Automatically use correct SSH key for remote Git repo](https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/)
    * [StackOverFlow](https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain)
    * [Connecting to GitHub with SSH](https://help.github.com/articles/connecting-to-github-with-ssh/)
    _Special thanks to [@pbuditi](https://github.com/pbuditi) for your help!_
  8. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -14,20 +14,20 @@ Assuming you are new to this like me, first I'd like to share with you that your
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, [or check if you have one](https://help.github.com/articles/checking-for-existing-ssh-keys/), continue on with the following for the second account.
    **1. Creating the SSH keys. For each SSH key pairs:**
    #### 1. Creating the SSH keys. For each SSH key pairs:
    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`, `user-2`. This step will generate both the private and public keys, `user-1` + `user-1.pub` , `user-2` + `user-2.pub` respectively.
    * [GitHub](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#generating-a-new-ssh-key) has this step in detail. We're not adding the keys to the ssh-agent.
    **2. Register your keys to the respective GitHub accounts.**
    #### 2. Register your keys to the respective GitHub accounts.
    * Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    **3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:**
    #### 3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:
    >```bash
    >#user1 account
    @@ -47,11 +47,11 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    >
    > Replace `user1` or `user2` with your GitHub usernames/identification-handlers
    **4. Go ahead to git clone the respective GitHub account**
    #### 4. Go ahead to git clone the respective GitHub account
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    **5. Configure your git identity:**
    #### 5. Configure your git identity:
    * Open up local git config using `git config --local -e`and add:
    >```bash
    @@ -60,7 +60,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    > email = [email protected]
    >```
    **6. Ensure your remote url is in the right format e.g: `[email protected]:user1/your-repo-name.git your-repo-name_user1`**
    #### 6. Ensure your remote url is in the right format e.g: `[email protected]:user1/your-repo-name.git your-repo-name_user1`
    * You either run `git remote set-url origin [email protected]:user1/your-repo-name.git your-repo-name_user1`
    * or amend your remote ssh-url in your local git config file:
    > ```bash
    @@ -71,7 +71,7 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    Now you can git actions (pull/push/fetch...etc) all you like!
    ### Resources:
    #### Resources:
    * [Automatically use correct SSH key for remote Git repo](https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/)
    * [StackOverFlow](https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain)
    * [Connecting to GitHub with SSH](https://help.github.com/articles/connecting-to-github-with-ssh/)
  9. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -61,11 +61,11 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    >```
    **6. Ensure your remote url is in the right format e.g: `[email protected]:user1/your-repo-name.git your-repo-name_user1`**
    * you either run `git remote set-url origin [email protected]:user1/your-repo-name.git your-repo-name_user1`
    * or you do so in your local git config file:
    * You either run `git remote set-url origin [email protected]:user1/your-repo-name.git your-repo-name_user1`
    * or amend your remote ssh-url in your local git config file:
    > ```bash
    > [remote "origin"]
    > url = [email protected]user-1:user-1/learn_mocha_chai.git
    > url = [email protected]user1:user1/your-repo-name.git
    >       fetch = +refs/heads/*:refs/remotes/origin/*
    > ```
  10. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -60,10 +60,16 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    > email = [email protected]
    >```
    **6. Ensure your remote url is in the right format!**
    * `[email protected]:user1/your-repo-name.git your-repo-name_user1
    Now you can git push and pull all you like!
    **6. Ensure your remote url is in the right format e.g: `[email protected]:user1/your-repo-name.git your-repo-name_user1`**
    * you either run `git remote set-url origin [email protected]:user1/your-repo-name.git your-repo-name_user1`
    * or you do so in your local git config file:
    > ```bash
    > [remote "origin"]
    > url = [email protected]:user-1/learn_mocha_chai.git
    >       fetch = +refs/heads/*:refs/remotes/origin/*
    > ```
    Now you can git actions (pull/push/fetch...etc) all you like!
    ### Resources:
    * [Automatically use correct SSH key for remote Git repo](https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/)
  11. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,8 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`, `user-2`. This step will generate both the private and public keys, `user-1` + `user-1.pub` , `user-2` + `user-2.pub` respectively.
    * [GitHub](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#generating-a-new-ssh-key) has this step in detail. We're not adding the keys to the ssh-agent.
    **2. Register your keys to the respective GitHub accounts.**
  12. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Assuming you are new to this like me, first I'd like to share with you that your
    > ForwardAgent yes
    >```
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, continue on with the following for the second account.
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, [or check if you have one](https://help.github.com/articles/checking-for-existing-ssh-keys/), continue on with the following for the second account.
    **1. Creating the SSH keys. For each SSH key pairs:**
    @@ -22,7 +22,8 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    **2. Register your keys to the respective GitHub accounts.**
    *Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    * Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    **3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:**
  13. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -20,11 +20,11 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`, `user-2`. This step will generate both the private and public keys, `user-1` + `user-1.pub` , `user-2` + `user-2.pub` respectively.
    *2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts.*
    **2. Register your keys to the respective GitHub accounts.**
    *Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    *3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:*
    **3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:**
    >```bash
    >#user1 account
  14. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 16 additions and 14 deletions.
    30 changes: 16 additions & 14 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -14,15 +14,15 @@ Assuming you are new to this like me, first I'd like to share with you that your
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, continue on with the following for the second account.
    *1. Creating the SSH keys. For each SSH key pairs:*
    **1. Creating the SSH keys. For each SSH key pairs:**
    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`. This step will generate both the private and public keys, `user-1` and `user-1.pub` respectively.
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`, `user-2`. This step will generate both the private and public keys, `user-1` + `user-1.pub` , `user-2` + `user-2.pub` respectively.
    *2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts.*
    *Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so
    *Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so.
    *3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:*
    @@ -41,26 +41,28 @@ Assuming you've got 2 github accounts, for work and play, lets get your Mac to _
    > IdentityFile ~/.ssh/github-user2
    > IdentitiesOnly yes
    >```
    >
    > Replace `user1` or `user2` with your GitHub usernames
    >
    > Replace `user1` or `user2` with your GitHub usernames/identification-handlers
    4. Go ahead to git clone the respective GitHub account
    **4. Go ahead to git clone the respective GitHub account**
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    5. Configure your git identity:
    * open up local git config `git config --local -e`and add:
    **5. Configure your git identity:**
    * Open up local git config using `git config --local -e`and add:
    ```bash
    [user]
    name = user1
    email = [email protected]
    ```
    >```bash
    >[user]
    > name = user1
    > email = [email protected]
    >```
    6. Ensure your remote url is in the format of `[email protected]:user1/your-repo-name.git your-repo-name_user1`
    **6. Ensure your remote url is in the right format!**
    * `[email protected]:user1/your-repo-name.git your-repo-name_user1
    Now you can git push and pull all you like!
    ### Resources:
    * [Automatically use correct SSH key for remote Git repo](https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/)
    * [StackOverFlow](https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain)
    * [Connecting to GitHub with SSH](https://help.github.com/articles/connecting-to-github-with-ssh/)
  15. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    The only way I've succeeded so far is to employ SSH.

    Navigate to `~/.ssh` and open up the `config` file. By default, it should look something like this:
    Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH `config` file in a `.ssh` directory and this is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account. You can navigate to it by running `cd ~/.ssh` within your terminal, open the `config` file with any editor, and by default it should look something like this:

    >```bash
    >Host *
    @@ -14,15 +14,17 @@ Navigate to `~/.ssh` and open up the `config` file. By default, it should look s
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, continue on with the following for the second account.
    1. Creating the SSH keys. For each SSH key pairs:
    *1. Creating the SSH keys. For each SSH key pairs:*
    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`. This step will generate both the private and public keys, `user-1` and `user-1.pub` respectively.
    2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts. Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so
    *2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts.*
    3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:
    *Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so
    *3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:*
    >```bash
    >#user1 account
  16. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 11 additions and 9 deletions.
    20 changes: 11 additions & 9 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,21 @@ The only way I've succeeded so far is to employ SSH.

    Navigate to `~/.ssh` and open up the `config` file. By default, it should look something like this:

    ```bash
    Host *
    AddKeysToAgent yes
    UseKeyChain yes
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ```
    >```bash
    >Host *
    > AddKeysToAgent yes
    > UseKeyChain yes
    > IdentityFile ~/.ssh/id_rsa
    > ForwardAgent yes
    >```
    Assuming you've got 2 github accounts, for work and play, lets get your Mac to _"register"_ them. To do that that you'll need to create SSH key pairs for each account. If you have already setup your Mac to SSH with one of them, continue on with the following for the second account.
    1. In order for your Mac to be identified by two different GitHub accounts, you'll need to create SSH key pairs for each account.
    1. Creating the SSH keys. For each SSH key pairs:
    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
    * This will prompt "Enter a file in which to save the key". The default suggested filename would be `id_rsa`. Remember to name the new file differently if you have any existing one, eg. `user-1`. This will generate a private and public key, `user-1` and `user-1.pub`, respectively.
    * You'll be prompted: "Enter a file in which to save the key" and the suggested default filename would be `id_rsa`. This filename will be used for your SSH private and public keys so remember to make it unique, eg. `user-1`. This step will generate both the private and public keys, `user-1` and `user-1.pub` respectively.
    2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts. Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so
  17. @Jonalogy Jonalogy revised this gist Jun 22, 2017. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    # Handling Multiple Github Accounts on MacOS

    The only way I succeededd so far is to employ SSH keys.
    The only way I've succeeded so far is to employ SSH.

    Navigate to `~/.ssh` and open up the `config` file. By default, it should look something like this:

    ```bash
    Host *
    AddKeysToAgent yes
    UseKeyChain yes
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ```
    ```bash
    Host *
    AddKeysToAgent yes
    UseKeyChain yes
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ```

    1. In order for your Mac to be identified by two different GitHub accounts, you'll need to create SSH key pairs for each account.

  18. @Jonalogy Jonalogy revised this gist Jun 21, 2017. 1 changed file with 21 additions and 16 deletions.
    37 changes: 21 additions & 16 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -22,26 +22,27 @@ Host *

    3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:

    >```bash
    >>#user1 account
    >Host github.com-user1
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user1
    > IdentitiesOnly yes
    >
    >#user2 account
    >Host github.com-user2
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user2
    > IdentitiesOnly yes
    >```
    >```bash
    >#user1 account
    >Host github.com-user1
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user1
    > IdentitiesOnly yes
    >
    >#user2 account
    >Host github.com-user2
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user2
    > IdentitiesOnly yes
    >```
    >
    > Replace `user1` or `user2` with your GitHub usernames
    4. Go ahead to git clone the respective GitHub account
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    5. Configure your git identity:
    * open up local git config `git config --local -e`and add:
    @@ -55,3 +56,7 @@ Host *
    6. Ensure your remote url is in the format of `[email protected]:user1/your-repo-name.git your-repo-name_user1`

    Now you can git push and pull all you like!

    ### Resources:
    * [Automatically use correct SSH key for remote Git repo](https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/)
    * [StackOverFlow](https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain)
  19. @Jonalogy Jonalogy revised this gist Jun 21, 2017. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -40,5 +40,18 @@ Host *
    >
    > Replace `user1` or `user2` with your GitHub usernames
    4. Go ahead to git clone the respective github account
    4. Go ahead to git clone the respective GitHub account
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    5. Configure your git identity:
    * open up local git config `git config --local -e`and add:
    ```bash
    [user]
    name = user1
    email = [email protected]
    ```
    6. Ensure your remote url is in the format of `[email protected]:user1/your-repo-name.git your-repo-name_user1`

    Now you can git push and pull all you like!
  20. @Jonalogy Jonalogy revised this gist Jun 21, 2017. 2 changed files with 44 additions and 1 deletion.
    44 changes: 44 additions & 0 deletions handling_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    # Handling Multiple Github Accounts on MacOS

    The only way I succeededd so far is to employ SSH keys.

    Navigate to `~/.ssh` and open up the `config` file. By default, it should look something like this:

    ```bash
    Host *
    AddKeysToAgent yes
    UseKeyChain yes
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ```

    1. In order for your Mac to be identified by two different GitHub accounts, you'll need to create SSH key pairs for each account.

    * run `ssh-keygen -t rsa -b 4096 -C "[email protected]"`

    * This will prompt "Enter a file in which to save the key". The default suggested filename would be `id_rsa`. Remember to name the new file differently if you have any existing one, eg. `user-1`. This will generate a private and public key, `user-1` and `user-1.pub`, respectively.

    2. Register the contents of the public key, e.g `user-1.pub`, into the respective GitHub accounts. Follow the [steps](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) here to do so

    3. Head back over to the SSH `config` file at `~/.ssh` and amend accordingly to:

    >```bash
    >>#user1 account
    >Host github.com-user1
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user1
    > IdentitiesOnly yes
    >
    >#user2 account
    >Host github.com-user2
    > HostName github.com
    > User git
    > IdentityFile ~/.ssh/github-user2
    > IdentitiesOnly yes
    >```
    >
    > Replace `user1` or `user2` with your GitHub usernames
    4. Go ahead to git clone the respective github account
    > `git clone [email protected]:user1/your-repo-name.git your-repo-name_user1`
    1 change: 0 additions & 1 deletion handlng_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    # Handling Multiple Github Accounts on MacOS
  21. @Jonalogy Jonalogy created this gist Jun 21, 2017.
    1 change: 1 addition & 0 deletions handlng_multiple_github_accounts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Handling Multiple Github Accounts on MacOS