Git Push 명령어 실행 시 발생하는 “리모트에 로컬에 없는 사항이 들어 있으므로 업데이트가 거부되었습니다.” 에러 해결

Git Push 명령어 실행 시 발생하는 “리모트에 로컬에 없는 사항이 들어 있으므로 업데이트가 거부되었습니다.” 라는 에러의 해결 방법을 정리해 봤습니다.
2022.12.01

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

안녕하세요 클래스메소드 김재욱(Kim Jaewook) 입니다. 이번에는 Git Push 명령어 실행 시 발생하는 “리모트에 로컬에 없는 사항이 들어 있으므로 업데이트가 거부되었습니다.” 라는 에러의 해결 방법을 정리해 봤습니다.

문제 발생

To https://github.com/xxxxxxxxx/xxxxxxxxx.git
! [rejected] main -> main (fetch first)
error: 레퍼런스를 'https://github.com/cxxxxxxxxx/xxxxxxxxx.git'에 푸시하는데 실패했습니다
힌트: 리모트에 로컬에 없는 사항이 들어 있으므로 업데이트가
힌트: 거부되었습니다. 이 상황은 보통 또 다른 저장소에서 같은
힌트: 저장소로 푸시할 때 발생합니다. 푸시하기 전에
힌트: ('git pull ...' 등 명령으로) 리모트 변경 사항을 먼저
힌트: 포함해야 합니다.
힌트: 자세한 정보는 'git push --help'의 "Note about fast-forwards' 부분을
힌트: 참고하십시오.

Git Push 명령어를 실행하자 다음 에러가 발생했습니다.

pull 명령어로 변경 사항을 로컬 환경에 포함해야 한다고 합니다.

문제 해결

git pull origin main

pull 명령어를 사용합니다.

힌트: You have divergent branches and need to specify how to reconcile them.
힌트: You can do so by running one of the following commands sometime before
힌트: your next pull:
힌트:
힌트: git config pull.rebase false # merge (the default strategy)
힌트: git config pull.rebase true # rebase
힌트: git config pull.ff only # fast-forward only
힌트:
힌트: You can replace "git config" with "git config --global" to set a default
힌트: preference for all repositories. You can also pass --rebase, --no-rebase,
힌트: or --ff-only on the command line to override the configured default per
힌트: invocation.

하지만 다음과 같은 에러가 발생합니다.

git config pull.rebase false
git config --global pull.ff true

둘 중 한가지 명령어를 사용한 다음, 다시 pull 명령어를 실행합니다.

해당 관련 사항에 대해서는 아래 링크를 참고해 주세요.

git config pull.rebase false
git pull origin main

https://github.com/xxxxxxxxx/xxxxxxxxx URL에서
* branch main -> FETCH_HEAD
Merge made by the 'ort' strategy.
.DS_Store | Bin 6148 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 .DS_Store

이렇게 git config pull.rebase false 명령어를 실행한 다음 pull 명령어를 실행하면 문제 없이 동작 하는 것을 확인할 수 있습니다.

git push -u origin main

오브젝트 나열하는 중: 8, 완료.
오브젝트 개수 세는 중: 100% (8/8), 완료.
Delta compression using up to 8 threads
오브젝트 압축하는 중: 100% (6/6), 완료.
오브젝트 쓰는 중: 100% (6/6), 2.08 KiB | 2.08 MiB/s, 완료.
Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.

마지막으로 Push 명령어를 사용하면 문제 없이 깃 리포지토리에 Push 되는 것을 확인할 수 있습니다.

본 블로그 게시글을 보시고 문의 사항이 있으신 분들은 클래스메소드코리아 (info@classmethod.kr)로 연락 주시면 빠른 시일 내 담당자가 회신 드릴 수 있도록 하겠습니다 !