<?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: Paulo de Tasso Oliveira de Lacerda</title>
    <description>The latest articles on DEV Community by Paulo de Tasso Oliveira de Lacerda (@tassolacerda).</description>
    <link>https://dev.to/tassolacerda</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%2F761671%2Ffbbb66f8-185b-4a6c-b0ef-79aacbdd582e.jpeg</url>
      <title>DEV Community: Paulo de Tasso Oliveira de Lacerda</title>
      <link>https://dev.to/tassolacerda</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tassolacerda"/>
    <language>en</language>
    <item>
      <title>Git config for multiple users (office/personal)</title>
      <dc:creator>Paulo de Tasso Oliveira de Lacerda</dc:creator>
      <pubDate>Mon, 19 Jun 2023 19:47:13 +0000</pubDate>
      <link>https://dev.to/tassolacerda/git-config-for-multiple-users-officepersonal-52ck</link>
      <guid>https://dev.to/tassolacerda/git-config-for-multiple-users-officepersonal-52ck</guid>
      <description>&lt;p&gt;Create the folders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/Development
   /github # personal projects
   /findme# work projects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create two files:&lt;/p&gt;

&lt;p&gt;~/.gitconfig-github&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .gitconfig-github

[user]
  email = paulodetasso@proton.me
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;~/.gitconfig-findme&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .gitconfig-findme

[user]
  email = paulo@findme.id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in ~/.gitconfig we will paste this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
  name = Paulo Lacerda
[init]
  defaultBranch = main

[includeIf "gitdir:~/Development/github/"]
  path = .gitconfig-github
[includeIf "gitdir:~/Development/findme/"]
  path = .gitconfig-findme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  SSH
&lt;/h3&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ~/.ssh
cd ~/.ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this code in terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa -C "paulodetasso@proton.me" -f "id_rsa_personal"
ssh-keygen -t rsa -C "paulo@findme.id" -f "id_rsa_work" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add ~/.ssh/id_rsa_personal
ssh-add ~/.ssh/id_rsa_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we need to configure SSH to understand when to use each key. To do that, we'll create a config file inside the .ssh folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/.ssh
touch config
code config # you can use vi, vim, nano, or your preferred text editor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the config file, you can edit it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Personal account as default
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal

# Work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, it uses "github" as the host, but if you're using GitLab, you can change it in both the Host and HostName lines. Additionally, you can have different configurations for different remote repositories within the same file.&lt;/p&gt;

&lt;p&gt;So, whenever you clone a repository, if it belongs to your work account, you just need to edit the URL to match the structure above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com-work:your_user/repo_name.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
    </item>
  </channel>
</rss>
