=> This is the example to configure the multiple github account . Here 3 different github accounts has been configured. They are for profession/work, personal and demo.
Linux File Folder Structure
- ~/
- .SSH [ Folder will be created automatically once ssh-keygen is exectued ]
- config [ File to create manually for all individual github or gitlab account with Host, HostName, User and IdentityFile]
- .gitconfig_mypersonal [ File to create manually for the details of username and email ]=> Git Config for GitHub Account 2
- .gitconfig_mydemo [ File to create manually for the details of username and email ]=> Git Config for GitHub Account 3
- id_rsa_mypersonal_github [ File created automatically when ssh-keygen is executed ]=> Git Account 1 – Private Key
- id_rsa_mypersonal_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 1 – Public Key
- id_rsa_myusername_github [ File created automatically when ssh-keygen is executed ]=> Git Account 2 – Private Key
- id_rsa_myusername_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 2 – Public Key
- id_rsa_mydemo_github [ File created automatically when ssh-keygen is executed ]=> Git Account 3 – Private Key
- id_rsa_mydemo_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 3 – Private Key
- known_hosts (no need to worry; will be created automatically)
- .gitconfig [ File to create manually for the details of username and email or automatically for default user with git config –global and add other user details ]
- .SSH [ Folder will be created automatically once ssh-keygen is exectued ]
Note: Linux ko sab thauma path deda forward slash (/) use garnu parcha instead of backward slash (\)
Windows File Folder Structure
- C:\Users\PCName\
- .SSH [ Folder will be created automatically once ssh-keygen is exectued ]
- config [ File to create manually for all individual github or gitlab account with Host, HostName, User and IdentityFile]
- .gitconfig_mypersonal [ File to create manually for the details of username and email ]=> Git Config for GitHub Account 2
- .gitconfig_mydemo [ File to create manually for the details of username and email ]=> Git Config for GitHub Account 3
- id_rsa_mypersonal_github [ File created automatically when ssh-keygen is executed ]=> Git Account 1 – Private Key
- id_rsa_mypersonal_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 1 – Public Key
- id_rsa_myusername_github [ File created automatically when ssh-keygen is executed ]=> Git Account 2 – Private Key
- id_rsa_myusername_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 2 – Public Key
- id_rsa_mydemo_github [ File created automatically when ssh-keygen is executed ]=> Git Account 3 – Private Key
- id_rsa_mydemo_github.pub [ File created automatically when ssh-keygen is executed ]=> Git Account 3 – Private Key
- known_hosts (no need to worry; will be created automatically)
- .gitconfig [ File to create manually for the details of username and email or automatically for default user with git config –global and add other user details ]
- .SSH [ Folder will be created automatically once ssh-keygen is exectued ]
Files
.gitconfig
# Default User Config Details
[user] # [ This is for default - Will be used for all git account unless specific folder is used or manually configured for the repo] name = Mero Name email = myoffice@gmail.com
# Config for My Personal Account – Tala specify gareko folder/subfoder (i.e. git_mypersonal) bhetra ko complete project will be used as git user configuration from the mentioned path as soon as .git is init under that folder
[includeIf "gitdir:D:/Workspace/git_mypersonal/"] path= C:/Users/PCName-PC/.ssh/.gitconfig_mypersonal
# Config for My Demo Account – Tala specify gareko folder/subfoder (i.e. git_mydemo) bhetra ko complete project will be used as git user configuration from the mentioned path as soon as .git is init under that folder
[includeIf "gitdir:D:/Workspace/git_mydemo/"] path= C:/Users/PCName-PC/.ssh/.gitconfig_mydemo
.SSH / config
Host github.com HostName github.com User git IdentityFile C:\Users\PCName-PC\.ssh\id_rsa_myoffice_github
Host github.com-mypersonal HostName github.com User git IdentityFile C:\Users\PCName-PC\.ssh\id_rsa_mypersonal_github
Host github.com-mydemo HostName github.com User git IdentityFile C:\Users\PCName-PC\.ssh\id_rsa_mydemo_github
.SSH / .gitconfig_mypersonal
[user] email = myusername@gmail.com name = MyRealName Sharma
.SSH / .gitconfig_mydemo
[user] email = mydemo@gmail.com name = MyPuraName Sharma
Generate SSH
ssh-keygen -t rsa -C myoffice@gmail.com