[git bash] hint: Updates were rejected because the tip of your current branch is behind 에러 해결하기

muz·2022년 9월 27일
0

Trouble-Shooting 🔨

목록 보기
11/11
post-thumbnail

😢 문제상황

로컬에서 작업하던 프로젝트를 깃허브 레포지토리와 연결하려던 중 에러가 발생했다.
우선 깃허브에 새 레포지토리를 생성한 상태였고, git remote를 이용해 해당 레포지토리와 연결해준 상태였다. 아래의 명령어를 입력해주었는데..

git push -u origin main

에러요????

To https://github.com/??/??.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/??/??.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

😎 해결 방법

해당 에러는 언제 발생하는가?

크게 2가지의 원인이 있는 듯하다.

  1. Github에서 repository 생성 시 README.md를 함께 생성시킨 경우
  2. 이미 push해놓은 파일이 있었거나, 일부 데이터가 손실된 경우

어떻게 해결했냐면 .. +

사실 해결 방법은 간단했다. 내 경우는 1번이었기 때문에 그냥 '+'를 이용해서 푸시해주었다.
더 빠른 방법으로는 강제 푸시가 있다. 저만 이러는거 아니잖아요 그쵸?

나는 master나 dev branch가 아니었어서 bash창에 아래와 같이 작성해주었다. branch명이 다르다면 main대신 설정한 branch명을 입력하면 된다.

git push -u origin +main

만약 강제로 푸시하고 싶다면 아래와 같이 입력하면 된다. 단 강제 푸시 시 기존에 올려놓은 파일들이 손상될 수 있음을 꼭 주의해야한다.

git push origin main -f
profile
Life is what i make up it 💨

0개의 댓글