깃허브 push 문제 생겼을 때 해결 방법 (Branch 충돌)

osohyun0224·2023년 3월 3일
0

ㅎㅎ 안녕하세요 주인장입니다. vue 초급 시리즈 작성중에 프로젝트 올리다가 오류났던 상황에 대한 해결 방법을 공유하고자 합니다. 깃에 프로젝트 올리는 명령어부터 상황해결 방법에 대해 다 작성할 예정이니 잘 읽어주세요

  1. 올리려는 파일 git bash에 접속한 후 아래의 명령어들 차례로 입력
git config --global user.name "본인 깃허브 아이디"

git config --global user.email "깃허브 이메일"
git init      # 파일 생성

git add .     #선택한 프로젝트 폴더 내의 모든 파일 관리

git status    #상태확인

git commit -m "커밋 메세지 아무거나"     #커밋
git remote add origin {깃허브 저장하는 주소}

git push -u origin master

여기서 아래의 오류가 나는데....

! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/osohyun0224/soldout_clonecoding.git' hint: updates were rejected because the remote contains work that you do hint: not have locally. this is usually caused by another repository pushing hint: to the same ref. you may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: see the 'note about fast-forwards' in 'git push --help' for details.

바로 깃허브 저장소의 기본 브랜치는 main인데 여기서는 master이기 때문이다.
아하 그럼
git push -u origin master에서 main으로 바꿔서 해주면 되는거 아님? 이라고 생각할 수 있는데 그러면 안된다 ㅋㅋㅋㅋㅋㅋ

이건 어떻게 해결해주냐면

깃허브 저장소에 가서 브랜치명을 main -> master로 변경

하고 나서 다시 위의 명령어들 치고 나면
또 아래의 오류가 나는데

To https://github.com/osohyun0224/SoldOut_CloneCoding.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/osohyun0224/SoldOut_CloneCoding.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

이때 오류가 나는 이유는 기존에 올려뒀던 데이터들의 손실을 막기 위해서 얘네가 자체적으로 막은 것이다.

해결 방법은 간단하다 그냥 바로 +를 붙여주면됨(너가 막아도 상관없어 강제로 푸시한다 약간 이런 느낌...)

git push origin +master

깔끔하게 오류 해결~

profile
학부생 Frontend Developer

0개의 댓글