본문 바로가기
TIL

Git multiple accounts / 깃 다중 계정

by cocacola0 2022. 4. 13.

Git Multiple Account Management

 

1. ssh generation

ssh-keygen -t rsa -C "user1@naver.com" -f "work"
ssh-keygen -t rsa -C "user2@gmail.com" -f "private"

2. Adding public key to each Git accounts

pbcopy < ~/.ssh/work.pub
pbcopy < ~/.ssh/private.pub

3. Register each ssh entries to ssh-agent 

# Check Currnet Entries
$ ssh-add -l 

# Register entry
$ ssh-add ~/.ssh/work
$ ssh-add ~/.ssh/private

4. Editing ~/.ssh/config  

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/<created_key>

5. Editing project gitconfig

# Path : <path_to_work_project>/.git/config

# Adding Last lines of [core] block
[core]
	.....
	sshCommand = "ssh -i ~/.ssh/work"
    
# Path : <path_to_private_project>/.git/config

# Adding Last lines of [core] block
[core]
	.....
	sshCommand = "ssh -i ~/.ssh/private"

automatically linking github accounts without changing  user.name, user.email  

 

======================

 

깃 다중계정 관리

 

1. ssh 생성

ssh-keygen -t rsa -C "user1@naver.com" -f "work"
ssh-keygen -t rsa -C "user2@gmail.com" -f "private"

2. 공개키 각각의 Git account 에 추가

pbcopy < ~/.ssh/work.pub
pbcopy < ~/.ssh/private.pub

3. ssh-agent 에 ssh entry 로 등록

# 현재 entry 확인 
$ ssh-add -l 

# entry 등록
$ ssh-add ~/.ssh/work
$ ssh-add ~/.ssh/private

4. ~/.ssh/config 파일 수정

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/<created_key>

5. 각 프로젝트 gitconfig 수정

# Path : <path_to_work_project>/.git/config

# 마지막줄에 추가 
[core]
	.....
	sshCommand = "ssh -i ~/.ssh/work"
    
# Path : <path_to_private_project>/.git/config

# 마지막줄에 추가 
[core]
	.....
	sshCommand = "ssh -i ~/.ssh/private"

 

    user.name, user.email  를 설정할 필요 없이 연결됨. 

 

ref: 

https://blog.gitguardian.com/8-easy-steps-to-set-up-multiple-git-accounts/

 

8 steps to manage multiple GitHub accounts | GitGuardian Blog

Any developer has to set up his Git config at least once. Our cheat sheet will help you make this process a breeze, ensuring that you never push with the wrong profile again!

blog.gitguardian.com

https://www.freecodecamp.org/news/git-config-how-to-configure-git-settings/

 

git config – How to Configure Git Settings to Improve Your Development Workflow

git config is a powerful command in Git. You can use the Git configuration file to customize how Git works. This file exists in the project level where Git is initialized ( /project/.git/config) or at the root level (~/.gitconfig). If no configurations are

www.freecodecamp.org

https://www.freecodecamp.org/news/git-config-how-to-configure-git-settings/

댓글