피드로 돌아가기
1Password, GitHub, and Git CLI with Multiple Users
Dev.toDev.to
DevOps

Git includeIf와 SSH Config를 활용한 다중 계정 자동 스위칭 설계

1Password, GitHub, and Git CLI with Multiple Users

Sean Boult2026년 5월 1일3beginner

Context

개인 프로젝트와 업무용 오픈소스 프로젝트를 단일 머신에서 동시에 운영함에 따른 계정 혼선 발생. 디렉토리 경로에 따라 Git Identity와 SSH Key, PAT(Personal Access Token)가 자동으로 전환되는 메커니즘의 부재로 인한 수동 설정의 번거로움 해결 필요.

Technical Solution

  • Git includeIf 조건부 설정을 통한 ~/oss/ 경로 내 업무용 .gitconfig-work 자동 로드 구조 설계
  • ~/oss 디렉토리를 Sentinel Repo로 초기화하여 gitdir 매칭 조건 충족 및 설정 활성화
  • SSH Config의 IdentityFile과 Git Core sshCommand 옵션을 통한 경로 기반 SSH Key 강제 지정
  • 1Password CLI Plugin을 활용하여 디렉토리 컨텍스트에 맞는 GitHub PAT 자동 매핑 및 인증 체계 구축
  • IdentitiesOnly yes 옵션 적용으로 SSH 에이전트의 무작위 키 시도를 방지하고 지정된 키만 사용하도록 제한

1. 업무용 프로젝트 전용 루트 디렉토리 생성 및 `git init`을 통한 Sentinel Repo 설정

2. `.gitconfig` 내 `includeIf "gitdir:~/path/"`를 통한 계정 분리 설정 적용

3. `~/.ssh/config`에 호스트별 `IdentityFile` 정의 및 Git `sshCommand` 연동 확인

4. 1Password 등 Secret Manager의 CLI 도구를 통한 환경별 API Token 자동화 검토

원문 읽기