- Github 저장소에 deploy key를 등록해두면 Github 로그인 패스워드 입력없이 push가 가능함
- Deploy key는 기본적으로 pull 권한만을 가지지만 push가 가능하도록 write 권한을 부여할 수 있음
- 키 신규 생성 또는 기존 키 사용
- 키 신규 생성
- 기존 키 사용
- ~/.ssh/id_rsa_myproject2.pub 파일을 열어서 내용을 복사
- id_rsa_myproject2가 아니라 id_rsa_myproject2.pub 파일
- Github의 개별 프로젝트의 Settings » Deploy keys » Add deploy key를 선택하여 키를 등록하면 됨
- id_rsa_myproject2.pub 파일의 내용을 붙여넣을 것
- Allow write access 항목도 체크할 것
- Add key 버튼을 클릭하여 저장
- 여러 git 저장소를 등록하려면 github.com이 여러 호스트인 것처럼 가짜 호스트로 분리하여 등록해줘야 함
Host myproject1.github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa_myproject1
Host myproject2.github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa_myproject2
Host myproject3.github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa_myproject3
- git 저장소를 https가 아니라 ssh로 접근하도록 origin을 변경해줘야 함
- 신규로 프로젝트를 clone할 때는 큰 문제가 없음
git clone [email protected]:terzeron/MyProject2.git
cd MyProject2.git
touch README
git add README
git commit -m "test"
git push
- clone되어 있는 기존 프로젝트를 push할 때는 문제가 발생할 수 있음
- 당연한 이야기지만 origin을 바꿔치기하려면 기존 origin과 동일한 상태(모든 변경이 merge/push된 상태)로 만들어두고 origin을 교체해야 함
git remote -v
git remote rm origin
git remote add origin [email protected]:terzeron/MyProjectWWW.git
git remote -v
git push -u origin master