Git Push Error Multi Accounts
Git Push 오류와 해결 방법 정리 (다중 GitHub 계정 설정)
개발 또는 GitOps 환경에서 GitHub 계정을 2개 이상 사용할 때, git push 명령어에서 다음과 같은 오류가 자주 발생할 수 있습니다.
❗ 오류 메시지
git push -u origin main
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
📌 원인 정리
이 에러는 보통 아래 중 하나의 원인입니다:
- 리포지토리 주소에 오타가 있거나 존재하지 않음
- GitHub 리포지토리가 비공개이고 권한이 없음
- 현재 SSH 인증된 계정과 리포지토리 주인이 다름
- SSH 키가 잘못 연결되어 있음
✅ 확인 방법
1. Git remote 주소 확인
git remote -v
2. SSH 인증된 GitHub 계정 확인
ssh -T git@github.com
-
출력 예:
Hi likebear09! You've successfully authenticated, but GitHub does not provide shell access.→ 현재
likebear09계정으로 SSH 연결됨
✅ SSH 키 분리 설정 방법
다음과 같이 .ssh/config 파일을 설정해 계정별로 키를 나눌 수 있습니다:
# likebear09 계정 (예: 기본 id_rsa 사용)
Host github-tigerlike
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# igotoo 계정 (예: 별도 id_ed25519 사용)
Host github-youtoo
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
✅ 리포지토리별 remote 설정 변경
# igotoo 계정을 쓰고 싶은 리포에서:
git remote set-url origin git@github-youtoo:youtoo/your-repo.git
# likebear09 계정을 쓰고 싶은 리포에서:
git remote set-url origin git@github-tigerlike:tigerlike/your-repo.git
✅ 커밋 작성자 정보도 디렉토리별로 설정
# 현재 Git 디렉토리에서만 설정
git config user.name "igotoo"
git config user.email "igotoo@example.com"
✅ 결과 검증
# 어떤 계정으로 연결되는지 확인
ssh -T github-igotoo
ssh -T github-likebear
🎉 정리
| 항목 | 확인 명령 |
|---|---|
| 현재 SSH 연결 계정 | ssh -T git@github.com |
| SSH 키별 연결 테스트 | ssh -i ~/.ssh/키파일 -T git@github.com |
| 리포 주소 변경 | git remote set-url origin git@github-xxx:계정/리포.git |
| 디렉토리별 사용자 설정 | git config user.name / email |
이 구성을 통해 여러 GitHub 계정을 깔끔하게 분리하여 git push 오류 없이 사용할 수 있습니다.