최근 회사에 입사하면서 Github Enterprise를 사용하면서, 기존에 사용하던 Git과 분리해야할 필요를 느꼈습니다.
매번 git clone하고 git config --local로 사내 계정 정보로 변경하는 것이 귀찮아져서
개인 디렉토리와 회사 디렉토리를 나눠 다른 계정으로 사용하는 방법을 찾아보았고 그 방법을 소개드립니다.
아래 소개하는 과정은 macOS 기준으로 작성되었습니다.
1. 홈 디렉토리로 이동하기
우선 터미널을 열고 ssh-keygen명령어를 입력합니다.
$ cd ~
2. .gitconfig 파일을 수정하기
원하시는 편집기로 .gitconfig 파일을 엽니다. 저 같은 경우는 vscode로 편집하겠습니다
[includeIf "gitdir:~/Personal/"]
path = .gitconfig-personal
[includeIf "gitdir:~/Work/"]
path = .gitconfig-work
앞으로 ~/Personal 하위 디렉토리들은 .gitconfig-personal에 적힌 내용으로 적용 될 것이고,
~/Work 의 하위 디렉토리들은 .gitconfig-work파일에 적힌 내용으로 적용 될 것입니다.
3. .gitconfig-personal, .gitconfig-work 파일 생성
[user]
email = aldehf420@naver.com
name = gohdong
[github]
user = gohdong
.gitconfig-personal에 개인용 깃 계정 정보를 입력하고 저장합니다.
[user]
email = donghyun.goh@navercorp.com
name = donghyun-goh
[github]
user = donghyun-goh
.gitconfig-work에 업무용 깃 계정 정보를 입력하고 저장합니다.