<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: K Bose</title>
    <description>The latest articles on DEV Community by K Bose (@k-bose).</description>
    <link>https://dev.to/k-bose</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F829897%2F87c245fa-39fb-49dd-a631-2d369ec8aa2f.jpg</url>
      <title>DEV Community: K Bose</title>
      <link>https://dev.to/k-bose</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/k-bose"/>
    <language>en</language>
    <item>
      <title>setup multiple git accounts on one local machine (2nd iteration)</title>
      <dc:creator>K Bose</dc:creator>
      <pubDate>Thu, 01 Dec 2022 18:08:51 +0000</pubDate>
      <link>https://dev.to/k-bose/setup-multiple-git-accounts-on-one-local-machine-2nd-iteration-5e2e</link>
      <guid>https://dev.to/k-bose/setup-multiple-git-accounts-on-one-local-machine-2nd-iteration-5e2e</guid>
      <description>&lt;p&gt;This post is in continuation of the &lt;a href="https://dev.to/kakarr0tt0/setup-multiple-git-accounts-on-one-local-machine-3akj"&gt;original post&lt;/a&gt; that will help you understand expected outcome if you decide to add additional git account to your local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I highly suggest you to head over to original post if you are doing this for first time. This post is only helpful for second or successive addition of git account to same local machine.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;u&gt;1. generate SSH key&lt;/u&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"your_professional_email@example.com"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I named my second key as &lt;code&gt;GitHub_key&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;u&gt;add passphrase to SSH key&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Running the above command will prompt for adding a passphrase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt; ~/.ssh/
&lt;span class="go"&gt;total 112
&lt;/span&gt;&lt;span class="gp"&gt;&amp;lt;snip&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="go"&gt;-rw-------   1 user  staff   484 Feb 29 13:26 GitHub_key
-rw-r--r--   1 user  staff   113 Feb 29 13:26 GitHub_key.pub
&lt;/span&gt;&lt;span class="gp"&gt;&amp;lt;snip&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Public - Private key pair will be generated in the &lt;code&gt;.ssh&lt;/code&gt; folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;u&gt;add SSH key to &lt;code&gt;ssh-agent&lt;/code&gt;&lt;/u&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="gp"&gt;ssh-add -K ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. &lt;u&gt;setup SSH &lt;code&gt;config&lt;/code&gt; file&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;From the previous post, file named as &lt;code&gt;config&lt;/code&gt; is present in the &lt;code&gt;.ssh&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;There are multiple ways to add the lines of text in this file, however I will provide with two of the easiest ways:&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1. add text from text editor
&lt;/h3&gt;

&lt;p&gt;I use &lt;code&gt;sublime text&lt;/code&gt; as my go to text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;subl ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;subl&lt;/code&gt; followed by the path name &lt;code&gt;~/.ssh/config&lt;/code&gt; will open the &lt;code&gt;config&lt;/code&gt; file in the sublime text editor.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the above lines of text as it is to the file and save it.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2. add text from the terminal
&lt;/h3&gt;

&lt;p&gt;In case you don't know how to open &lt;code&gt;config&lt;/code&gt; file in text editor, you can get this on the terminal itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Host *"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  AddKeysToAgent yes"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  UseKeychain yes"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  IdentityFile ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your config file should look like the below snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Host *
  AddKeysToAgent yes
  UseKeychain yes
&lt;/span&gt;&lt;span class="gp"&gt;  IdentityFile ~/.ssh/&amp;lt;ssh_key_name&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="go"&gt;
Host *
  AddKeysToAgent yes
  UseKeychain yes
&lt;/span&gt;&lt;span class="gp"&gt;  IdentityFile ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. &lt;u&gt;copy SSH public key&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;You need to copy the contents of the generated public key to add the SSH key to the Git Service Provider account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;pbcopy &amp;lt; ~/.ssh/&amp;lt;ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. &lt;u&gt;create workspace&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Below is the Folder Structure I am using as my workspace to neatly divide the multiple git service provider repos.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/~/
    |__.gitconfig
    |__/git_repos/
        |__GitHub/
            |__.gitconfig.GitHub
        |__GitLab/
            |__.gitconfig.GitLab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can structure your workspace in any way but remember the path for the additional &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt;. These git configs are going to override the global git config.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;u&gt;setup git config&lt;/u&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; user.email &amp;lt;your_github_email@example.com&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; user.name &amp;lt;your_user_name&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; github.user &amp;lt;your_github_user_name&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; core.sshCommand &lt;span class="s2"&gt;"ssh -i ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running all the &lt;code&gt;git config&lt;/code&gt; commands your &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt; file should look like the below snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/git_repos/GitHub/.gitconfig.GitHub

[user]
    email = &amp;lt;your_github_email@example.com&amp;gt;
    name = &amp;lt;your_user_name&amp;gt;
[github]
    user = &amp;lt;your_github_name&amp;gt;
[core]
    sshCommand = ssh -i ~/.ssh/&amp;lt;2nd_ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you need to specify the additional &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt; file in the Global &lt;code&gt;.gitconfig&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; includeIf.&lt;span class="s2"&gt;"gitdir:~/git_repos/GitHub/"&lt;/span&gt;.path ~/git_repos/GitHub/.gitconfig.GitHub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You Global &lt;code&gt;.gitconfig&lt;/code&gt; should now look like the below snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;snip&amp;gt;
[includeIf "gitdir:~/git_repos/GitLab/"]
    path = /Users/mac_user/git_repos/GitLab/.gitconfig.GitLab
[includeIf "gitdir:~/git_repos/GitHub/"]
    path = /Users/mac_user/git_repos/GitHub/.gitconfig.GitHub
&amp;lt;snip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have snipped the output of what Global &lt;code&gt;.gitconfig&lt;/code&gt; could look like to avoid confusion as your &lt;code&gt;.gitconfig&lt;/code&gt; may have some more config (which is fine).&lt;/p&gt;

</description>
    </item>
    <item>
      <title>setup multiple git accounts on one local machine</title>
      <dc:creator>K Bose</dc:creator>
      <pubDate>Thu, 01 Dec 2022 18:05:59 +0000</pubDate>
      <link>https://dev.to/k-bose/setup-multiple-git-accounts-on-one-local-machine-3akj</link>
      <guid>https://dev.to/k-bose/setup-multiple-git-accounts-on-one-local-machine-3akj</guid>
      <description>&lt;p&gt;Developers now-a-days have multiple Git Service Provider Accounts. I use GitLab for my personal projects &amp;amp; GitHub for professional repos. This tutorial applies to people who would like to setup multiple GitLab/GitHub/BitBucket on their machine.&lt;/p&gt;

&lt;p&gt;My local machine specifics at the time of writing this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;span class="go"&gt;git version 2.38.1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;sw_vers
&lt;span class="go"&gt;ProductName:        macOS
ProductVersion:     13.0
BuildVersion:       22A380
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;u&gt;1. generate SSH key&lt;/u&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"your_personal_email@example.com"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; ~/.ssh/&amp;lt;ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ssh-keygen&lt;/code&gt; generates the authentication keys for SSH. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t&lt;/code&gt; flag specifies the type of key to be generated. In this case the type is &lt;code&gt;ed25519&lt;/code&gt;. ED25519 is the recommended cryptographic public-key signature system. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-C&lt;/code&gt; flag is for adding a comment. In this case it will be your email. You may replace &lt;code&gt;your_personal_email@example.com&lt;/code&gt; with your git service provider email. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-f&lt;/code&gt; flag specifies the file name of the key that will be generated. You may replace &lt;code&gt;&amp;lt;ssh_key_name&amp;gt;&lt;/code&gt; with your own key name. I named it &lt;code&gt;GitLab_key&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. &lt;u&gt;add passphrase to SSH key&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Running the above command will prompt for adding a passphrase. Even though the process makes this step optional, it is highly recommended from security standpoint. Keys with pass phrase may not get compromised even if someone gains access to your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt; ~/.ssh/
&lt;span class="go"&gt;total 112
&lt;/span&gt;&lt;span class="gp"&gt;&amp;lt;snip&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="go"&gt;-rw-------   1 user  staff   484 Feb 29 13:26 GitLab_key
-rw-r--r--   1 user  staff   113 Feb 29 13:26 GitLab_key.pub
&lt;/span&gt;&lt;span class="gp"&gt;&amp;lt;snip&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Public - Private key pair will be generated in the &lt;code&gt;.ssh&lt;/code&gt; folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;u&gt;add SSH key to &lt;code&gt;ssh-agent&lt;/code&gt;&lt;/u&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="gp"&gt;ssh-add -K ~/.ssh/&amp;lt;ssh_key_name&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;eval&lt;/code&gt; executes the argument as shell command. The argument here is &lt;code&gt;$(ssh-agent -s)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&amp;amp; \&lt;/code&gt; allows you to enter another command in the next line before evaluating the argument and executing the command.&lt;/li&gt;
&lt;li&gt;The next line will output &lt;code&gt;cmdand&amp;gt;&lt;/code&gt; where you will have to enter &lt;code&gt;ssh-add -K ~/.ssh/&amp;lt;ssh_key_name&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ssh-add&lt;/code&gt; will add the mentioned identity file to the authentication agent. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-K&lt;/code&gt; is a deprecated version of Mac OS's 12 and newer &lt;code&gt;--apple-use-keychain&lt;/code&gt; flag. For now either one works. Both these flags stores the passphrase in your keychain when you add an SSH key to the ssh-agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Just like before you may replace &lt;code&gt;&amp;lt;ssh_key_name&amp;gt;&lt;/code&gt; with your own key name.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. &lt;u&gt;setup SSH &lt;code&gt;config&lt;/code&gt; file&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Check if file named as &lt;code&gt;config&lt;/code&gt; is present in the &lt;code&gt;.ssh&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If config file is not present in the &lt;code&gt;.ssh&lt;/code&gt; folder then create one.&lt;/strong&gt; &lt;code&gt;touch&lt;/code&gt; will create &lt;code&gt;config&lt;/code&gt; file in the &lt;code&gt;~/.ssh/&lt;/code&gt; directory path.&lt;/p&gt;

&lt;p&gt;There are multiple ways to add the lines of text in this file, however I will provide with two of the easiest ways:&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1. add text from text editor
&lt;/h3&gt;

&lt;p&gt;I use &lt;code&gt;sublime text&lt;/code&gt; as my go to text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;subl ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;subl&lt;/code&gt; followed by the path name &lt;code&gt;~/.ssh/config&lt;/code&gt; will open the &lt;code&gt;config&lt;/code&gt; file in the sublime text editor.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/&amp;lt;ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the above lines of text as it is to the file and save it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Just like before you may replace &lt;code&gt;&amp;lt;ssh_key_name&amp;gt;&lt;/code&gt; with your own key name.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4.2. add text from the terminal
&lt;/h3&gt;

&lt;p&gt;In case you don't know how to open &lt;code&gt;config&lt;/code&gt; file in text editor, you can get this on the terminal itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Host *"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  AddKeysToAgent yes"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  UseKeychain yes"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  IdentityFile ~/.ssh/&amp;lt;ssh_key_name&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;echo&lt;/code&gt; will pass the string to the file mentioned in the path &lt;code&gt;~/.ssh/config&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; will overwrite the whole contents of the mentioned file with the passed string mentioned inside the double quotes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; will append the string to the mentioned file at the end.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. &lt;u&gt;copy SSH public key&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;You need to copy the contents of the generated public key to add the SSH key to the Git Service Provider account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;pbcopy &amp;lt; ~/.ssh/&amp;lt;ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pbcopy&lt;/code&gt; is equivalent to &lt;code&gt;ctrl+c&lt;/code&gt; in mac terminal. It will copy the contents of the file mentioned the path &lt;code&gt;~/.ssh/&amp;lt;ssh_key_name&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. &lt;u&gt;create workspace&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Global &lt;code&gt;.gitconfig&lt;/code&gt; is present in the home directory of your machine. &lt;code&gt;~&lt;/code&gt; pronounced as &lt;em&gt;til·​de&lt;/em&gt; is shorthand for contents of the environment variable &lt;code&gt;HOME&lt;/code&gt; or by default the home directory in Unix (including Mac) machines.&lt;br&gt;
Below is the Folder Structure I am using as my workspace to neatly divide the multiple git service provider repos.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/~/
    |__.gitconfig
    |__/git_repos/
        |__GitHub/
            |__.gitconfig.GitHub
        |__GitLab/
            |__.gitconfig.GitLab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can structure your workspace in any way but remember the path for the additional &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt;. These git configs are going to override the global git config.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;u&gt;setup git config&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Out of the two options, adding config via a text editor vs git config command entry; I choose the latter. That is because adding config via text editor has always been a hit or miss for me. This problem was one of the motivations as well for me in writing this post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; user.email &amp;lt;your_gitlab_email@example.com&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; user.name &amp;lt;your_user_name&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; gitlab.user &amp;lt;your_gitlab_user_name&amp;gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; core.sshCommand &lt;span class="s2"&gt;"ssh -i ~/.ssh/&amp;lt;ssh_key_name&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git config&lt;/code&gt; will set the specified git configuration to the file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-f&lt;/code&gt; option lets you choose specified &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt; file in which the configuration will be stored.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--all&lt;/code&gt; option adds a new line to the configuration file without altering the previously written values.&lt;/li&gt;
&lt;li&gt;Values from &lt;code&gt;user.name&lt;/code&gt; &amp;amp; &lt;code&gt;user.email&lt;/code&gt; variables ends up in the author and committer field of commits.&lt;/li&gt;
&lt;li&gt;Value in &lt;code&gt;gitlab.user&lt;/code&gt; variable should be your GitLab Username. &lt;/li&gt;
&lt;li&gt;Value in &lt;code&gt;sshCommand&lt;/code&gt; specifies the exact Identity file (using &lt;code&gt;-i&lt;/code&gt; flag for &lt;code&gt;ssh&lt;/code&gt;) that needs to be used for a particular repo.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/git_repos/GitLab/.gitconfig.GitLab

[user]
    email = &amp;lt;your_gitlab_email@example.com&amp;gt;
    name = &amp;lt;your_user_name&amp;gt;
[gitlab]
    user = &amp;lt;your_gitlab_name&amp;gt;
[core]
    sshCommand = ssh -i ~/.ssh/&amp;lt;ssh_key_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After running all the &lt;code&gt;git config&lt;/code&gt; commands your &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt; file should look like the above snippet.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You may replace all the value with your own that are within &lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you need to specify the additional &lt;code&gt;.gitconfig.&amp;lt;name&amp;gt;&lt;/code&gt; file in the Global &lt;code&gt;.gitconfig&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-f&lt;/span&gt; .gitconfig.&amp;lt;name&amp;gt; &lt;span class="nt"&gt;--add&lt;/span&gt; includeIf.&lt;span class="s2"&gt;"gitdir:~/git_repos/GitLab/"&lt;/span&gt;.path ~/git_repos/GitLab/.gitconfig.GitLab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;includeIf.&amp;lt;condition&amp;gt;.path&lt;/code&gt; variable can include additional git config file is the condition is True. Here the condition is if git directory - &lt;code&gt;gitdir:&lt;/code&gt; is &lt;code&gt;~/git_repos/GitLab/&lt;/code&gt; and if it's True then the git config file specified in the &lt;code&gt;path&lt;/code&gt; will be used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;snip&amp;gt;
[includeIf "gitdir:~/git_repos/GitLab/"]
    path = /Users/mac_user/git_repos/GitLab/.gitconfig.GitLab
&amp;lt;snip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have snipped the output of what Global &lt;code&gt;.gitconfig&lt;/code&gt; could look like to avoid confusion as your &lt;code&gt;.gitconfig&lt;/code&gt; may have some more config (which is fine).&lt;/p&gt;

&lt;h2&gt;
  
  
  8. &lt;u&gt;repeat the steps to setup another account&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;You can repeat these step for additional account from the same/different service provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git config &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will list all the variable and their values in the .gitconfig file.&lt;/p&gt;




&lt;p&gt;In case you are facing issues in adding another account while/after repeating the above steps then head over to &lt;a href="https://dev.to/kakarr0tt0/setup-multiple-git-accounts-on-one-local-machine-2nd-iteration-5e2e"&gt;2nd iteration post&lt;/a&gt; to understand what is the expected outcome.&lt;/p&gt;

&lt;p&gt;I would like to mention this post by &lt;strong&gt;&lt;em&gt;Thomas Segura&lt;/em&gt;&lt;/strong&gt; - &lt;a href="https://blog.gitguardian.com/8-easy-steps-to-set-up-multiple-git-accounts/" rel="noopener noreferrer"&gt;8 Easy Steps to Set Up Multiple GitHub Accounts&lt;/a&gt; which initially helped me in understanding how it needs to be done. I ran into couple of problems that resulted in writing this post with tweaks to some of the steps mentioned in Thomas's Post. I am not a technical writer but he is; so if you can header over to his post and please show the guy some love.&lt;/p&gt;

</description>
      <category>gratitude</category>
      <category>motivation</category>
    </item>
  </channel>
</rss>
