TIL 20220708 한 컴퓨터에서 github 계정 여러개 사용하기

jiffydev·2022년 7월 8일
0

https://yangeok.github.io/git/2020/03/08/ssh-multiple-account.html

이 글에 대부분이 나와 있지만 헷갈렸던 부분만 몇개 정리.

ssh config 작성하기 관련

.ssh/config에 아래와 같이 작성한다.

# 변경 전
# 개인용 계정
Host personal
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_personal

# 회사용 계정
Host work
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_work

그런데 Host를 저렇게 설정해 놓으니 자주 사용하는 work 계정도 git clone git@{Host}:{User}/{Repository}.git 할 때 매번 바꿔줘야 하는 점이 좀 그랬다.
그래서 자주 쓰는 work는 github.com으로 해놓고 personal계정도 github.com-personal로 설정해서, 복사한 ssh 주소 뒤에 -personal만 붙이면 되도록 했다.

# 변경 후
# 개인용 계정
Host github.com-personal
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_personal

# 회사용 계정
Host github.com
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_work

gitconfig, gitconfig-* 작성하기 관련

위 블로그에는 .gitconfig에 아래처럼 작성하도록 되어 있었다.

[includeIf "gitdir:~/JOB/"]
 path = .gitconfig-work
[includeIf "gitdir:~/TEST/"]
 path = .gitconfig-personal
[includeIf "gitdir:~/Y/"]
 path = .gitconfig-personal

그리고 나는 .gitconfig-work, .gitconfig-personal은 당연히 설정할 해당 디렉터리(JOB, TEST, Y같은..) 아래에 두는 것인줄 알았는데 path에서 그렇게 되도록 설정을 해주거나, 예시를 그대로 사용하고자 한다면.gitconfig와 같은 디렉터리에 두어야 한다.

profile
잘 & 열심히 살고싶은 개발자

0개의 댓글