본문 바로가기
Tool/형상관리 & CI

[Git] push 실패(updates were rejected because the tip of your current branch is behind its counterpart)

by 댓츠굿 2020. 3. 9.

문제점

원격저장소에 push를 하려니 다음과 같은 에러가 났다.

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

 

원인

원격저장소 최신상태를 pull을 하고난 후 작업을 했어야 했는데 그러지 않아서 발생한 문제였다.

그래서 pull 명령어를 실행하니 다음과 같은 오류가 발생하였다.

From https://github.com/repo/some-project.git

 * branch            master     -> FETCH_HEAD

fatal: refusing to merge unrelated histories

 

해결책

--allow-unrelated-histories 옵션을 추가하여 다시 pull 명령어를 실행하니 문제를 해결할 수 있었다.

  • git pull <remote> <branch> --allow-unrelated-histories

이 옵션은 각자 다르게 시작된 두 프로젝트의 기록(history)을 병합하는 드문 상황에 사용된다고 한다.

 

참조 ) https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase

 

반응형