로컬저장소와 원격저장소(git repository) 동기화를 위해 git pull
명령어를 사용하면 fatal: refusing to merge unrelated histories와 같은 에러가 발생합니다.
> git pull origin master
From https://gitlab.tistory.com/Diagnocs/serv/oem/service_test
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
git pull
명령어로 로컬저장소와 원격저장소(git repository)를 동기화 할때 아래와 같이 수행됩니다.
- fetch로 원격저장소 데이터를 가져온다.
- 가져온 데이터를 로컬저장소에 merge한다.
merge를 수행할때 로컬저장소와 원격저장소간에 공통된 커밋 포인트가 있어야 하는데 없기 때문에 git pull 명령어 수행시 위와 같은 에러가 발생하게 됩니다.
에러 해결가이드 (refusing to merge unrelated histories)
1. 명령어에 --allow-unrelated-histories 옵션
git에서 서로 관련이 없는 저장소를 병합할 경우 오류가 발생할 수 있어 이를 방지하고 있습니다.
git pull 명령어에 --allow-unrelated-histories 옵션을 주면 연관이 없는 저장소 병합을 허용하게 해주어 간단하게 해결이 됩니다.
> git pull origin master --allow-unrelated-histories
(master가 입력된 곳에 branch name이 들어가도 됩니다.)
2. git clone 명령어 수행
다른 공간에 원격 저장소를 복제해와서 변경이 필요한 데이터를 추가하여 저장을 진행합니다.
> git clone 원격저장소 주소
함께보면 좋은자료
> git push error: failed to push some refs to 해결가이드
git push error: failed to push some refs to 해결가이드
초기 git 프로젝트 셋팅후에 작업을 진행할때 error: failed to push some refs to 'repo' 와 같은 오류를 한번씩 보셨을겁니다. 이는 원격저장소(gitlab/github)에 새로운 신규 파일이 생성되었고, 로컬저장소(
iliveinseoul.tistory.com
'프로그래밍 > Git' 카테고리의 다른 글
[Git] add LF will be replaced by CRLF warning 해결 (0) | 2023.07.07 |
---|---|
gitlab merge conflicts 해결 방법 (0) | 2023.02.21 |
[git] 생성부터 원격 저장소로 push하기 (add, remote, pull, commit) (0) | 2023.02.08 |
git push error: failed to push some refs to 해결가이드 (0) | 2022.07.19 |
[Git] Clone SSL certificate problem 오류 해결가이드 (0) | 2022.07.11 |
댓글