Back-End TIL/Git, Github

220920 Github 에러

BEstyle 2022. 9. 20. 14:47

 


로컬 저장소에 있는 프로젝트를 깃허브 사이트를 통해 만든 저장소로 push 하는 경우에 이런 메세지가 뜨는 경우가 있다.

 

1
2
3
4
5
6
7
8
C:\Users\gitProject>git push origin master
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/userId/userProject.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.
cs

 

 

push 전에 먼저 pull을 해서 프로젝트를 병합해 주어야 한다. 

 

1
 refusing to merge unrelated histories
cs

 

pull 명령 실행시 이런 문구와 함께 진행되지 않는다면, 다음의 명령으로 실행한다.

 

1
git pull origin 브런치명 --allow-unrelated-histories
cs

 

--allow-unrelated-histories   이 명령 옵션은 이미 존재하는 두 프로젝트의 기록(history)을 저장하는 드문 상황에 사용된다고 한다. 즉, git에서는 서로 관련 기록이 없는 이질적인 두 프로젝트를 병합할 때 기본적으로 거부하는데, 이것을 허용해 주는 것이다.

 

 


해결:

아 그럼 remote repo와 현재 local의 상태가 달라서 생긴 오류입니다.
remo repo.에서 직접 작업하시면 서로 상태가 다르기 때문에 오류가납니다.
둘의 상태를 일치시켜주기 위해서 먼저 pull하고 push해보세요
 
 
 
네 상태가 달라서 그런거같아서 pull을 했는데도 오류가 납니다..

 

 

git pull origin 브런치명 --allow-unrelated-historie