본문 바로가기
기타/Git

[Git Error] error: failed to push some refs to "http://github.~"

by jungmin.park 2024. 3. 20.

 

문제

처음 로컬에서 git init 입력 후 원격으로 git push -uf origin main으로 하려고 했을때 

Enumerating objects: 7379, done.
Counting objects: 100% (7379/7379), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5010/5010), done.
Writing objects: 100% (7379/7379), 15.01 MiB | 97.88 MiB/s, done.
Total 7379 (delta 1593), reused 7379 (delta 1593), pack-reused 0
remote: Resolving deltas: 100% (1593/1593), done.
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://gitlab.redwoodk.com/jeongmin-bak/hw2.extjs.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'http://github.~/[저장소 이름].git'

 

해결

원격 history와 로컬 history가 맞지 않아서 발생한 문제

git pull origin main --allow-unrelated-histories

 

--allow-unrelated-histories

이미 존재하는 두 프로젝트의 기록(history)을 저장하는 드문 상황에 사용된다.

git에서는 서로 관련 기록이 없는 이질적인 두 프로젝트를 병합할 때 기본적으로 거부하는데 이것을 허용해주는 것이다.