[Github] Permission to {B-account}/{repository-name}.git denied to {A-account}. / personal-access-token 활용한 해결책
배경&환경)
{A-account} 와 {B-account} 두 개의 github 계정을 사용하고 있다.
평소 {B-account} 계정으로 작업을 하고 있었고, {A-account} 계정을 사용하려던 중이였다.
의도)
{B-account} github으로 "remote" repository를 설정하고, "git push" 명령을 수행하려한다.
문제상황)
git config --global user.name {B-account} git config --global user.email {B-account}@gmail.com "config --global" 설정을 통해, {B-account} 로 변경한 상태였다.
하지만 아래와 같이, {A-account}로 {B-account} repository에 접근이 허가되지 않는다는 에러메시지가 나왔다.
ui-MacBookPro dockerfile % git push -u origin main remote: Permission to {B-account}/{repository-name}.git denied to {A-account}. fatal: unable to access 'https://github.com/{B-account}/{repository-name}.git/': The requested URL returned error: 403
원인)
This error means the key you are pushing with is attached to another repository as a deploy key, and does not have access to the repository you are trying to push to.
=> 현재 key는 {B-account} 키로 되어 있어서 {A-account} github 로 push를 할 수 없는 상태를 말한다.
해결방안)
personal-access-token을 활용해 "remote-repository"를 설정 후, 다시 "git push"를 진행했다.
// 기존 remote repository 정보 조회 ui-MacBookPro dockerfile % git remote -v origin https://github.com/{A-account}/{repository-name}.git (fetch) origin https://github.com/{A-account}/{repository-name}.git (push)
// 기존 remote repository 정보 제거 ui-MacBookPro dockerfile % git remote remove origin
// 기존 remote repository 정보 조회(삭제 확인) ui-MacBookPro dockerfile % git remote -v
// 기존 remote repository 정보 추가(Personal access tokens 추가) ui-MacBookPro dockerfile % git remote add origin https://{Personal access tokens}@github.com/{A-account}/{repository-name}.git ui-MacBookPro dockerfile % git remote -v origin https://{Personal access tokens}@github.com/{A-account}/{repository-name}.git (fetch) origin https://{Personal access tokens}@github.com/{A-account}/{repository-name}.git (push) ui-MacBookPro dockerfile % git push fatal: The current branch main has no upstream branch. To push the current branch and set the remote as upstream, use