Local use of multiple GitHub accounts

Original link: https://blog.forecho.com/local-use-of-multiple-github-accounts.html

introduction

If you are also trying Github hosting code in the company, you may encounter a problem, using your personal account and company account locally at the same time.

Then this article will share with you how to use multiple Github accounts locally at the same time.

ssh configuration

Generate the ssh needed for the job

By default, you already have a personal ssh key, if not, you need to generate a personal ssh key first.

 1 
 ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/work

configure host

 1 
 vim ~/.ssh/config 
 1 2 3 4 5 6 7 8 9 10 11 
 Host * ServerAliveInterval 60 #default github Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa Host w.github.com HostName github.com IdentityFile ~/.ssh/work

use

If you want to use the work key, then clone the code like this

 1 
 git clone [email protected]:work/xxx.git

Configuring Git User Issues

Cancel the global optional first

 1 2 
 git config --global --unset user.name git config --global --unset user.email

Configure Personal SSH

 1 
 vim ~/.gitconfig 
 1 2 3 4 5 6 
 [user] name = forecho email = [email protected] [includeIf "gitdir:~/work/"] path = ~/work/.gitconfig

The working directory is set separately

 1 
 vim ~/work/.gitconfig 
 1 2 3 
 [user] name = work email = [email protected]

examine

 1 
 git config --list

This article is transferred from: https://blog.forecho.com/local-use-of-multiple-github-accounts.html
This site is only for collection, and the copyright belongs to the original author.