원격 저장소에 main 브랜치만 있고 user1 이 없는 경우 git push 할 때 오류가 발생한다.
오류 내용은 다음과 같다.
fatal: The current branch user1 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin user1
로컬 브랜치 user1 을 원격에 연결시켜야 한다. 원격 저장소에 user1 브랜치를 생성하고 업스트림 브랜치로 설정을 하려면 아래 명령을 실행해야 한다.
git push --set-upstream origin user1
이때 다음과 같은 에러가 발생했다.
비밀번호를 사용한 인증을 2021년 8월 13일 이후로 지원하지 않기 때문에 토큰이나 SSH키를 이용해야 한다. SSH키 인증을 이용하려 했는데 여전히 같은 에러가 발생했다. 이를 해결하려면 Git의 원격 URL을 HTTPS에서 SSH로 변경해야 한다.
Git 원격 URL을 SSH 방식으로 변경
먼저, 현재 원격 URL을 확인한다.
git remote -v
HTTPS 방식이라면 다음과 같이 나타날 것이다.
origin https://github.com/jiyun0205/git_study.git (fetch)
origin https://github.com/jiyun0205/git_study.git (push)
원격 URL을 SSH 방식으로 변경해야 한다.
git remote set-url origin git@github.com:jiyun0205/git_study.git
다시 확인을 한다.
git remote -v
# 아래와 같은 결과가 확인된다.
# origin git@github.com:jiyun0205/git_study.git (fetch)
# origin git@github.com:jiyun0205/git_study.git (push)
git push를 한다.
git push --set-upstream origin user1