개발 기타/개발 환경

[SourceTree] fail to push some refs to 오류 해결

쫑인스 2022. 2. 21. 01:07

포스팅 목적

소스트리를 사용하다가 branch 를 merge 한 후 main branch 에 push 할 것이 4건 있다고 나와있어서 push 버튼을 눌렀더니 아래와 같이 failed to push some refs to 오류가 발생했습니다.

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags origin main:main
Pushing to "레포지토리"
To "레포지토리"
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to "레포지토리"

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.

 

문제 발생 원인

해당 오류는 원격저장소에 로컬에는 없는 파일이 있을 때, push 하면 발생하는 오류라고 합니다. 이번 작업에는 저 혼자만 작업을 했기 때문에 로컬에 없는 파일이 있어서 발생한 문제는 아닙니다.

다만 GitHub 에서 PR 을 통해 main branch 에 merge 를 했기 때문에 GitHub 에 commit 한 소스가 다 올라가 있었는데도 소스트리 상에는 다르게 표시되고 있었습니다. 이 현상은 나중에 재현을 해서 정확히 원인을 파악해 봐야 할 것 같습니다.

 

해결 방법

pull 로 update 해주었더니 (애초부터 push 할 건은 없었기 때문에) push 할 것이 없어졌습니다.

 

참고 자료