[트러블슈팅/GitHub] 원격저장소 - 로컬저장소 기록(history) 병합

2026. 1. 17. 19:06·트러블슈팅

문제

원격 저장소에 리포지터리 작성 후 로컬에 있던 프로젝트를 push 하려는데 아래와 같은 오류 메시지 등장

! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to '깃허브링크'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

원인

로컬 브랜치와 원격 브랜치의 히스토리가 달라서 발생

GitHub에서 리포지토리를 생성할 때 README나 .gitignore를 추가했다면 이런 상황이 발생할 수 있음

로컬에서 git pull을 먼저 진행 후 push 하면 됨

 

이때 git pull을 진행하려고 하면 아래 오류 메시지가 뜨면서 진행이 안 될 수 있음

fatal: refusing to merge unrelated histories

 

마찬가지로 로컬 브랜치와 원격 브랜치의 히스토리가 달라서 발생함

공통된 커밋 포인트가 없기 때문

 

해결

pull 명령어에 `--allow-unrelated-histories` 옵션 추가해서 강제 pull 받아오기

 git pull origin 브랜치명 --allow-unrelated-histories

나 같은 경우 로컬 저장소에서 작성한 파일 내용이 날아갈까봐 원격 저장소의 README, gitignore 파일 삭제 후 git pull을 진행 함

근데 이럴 필요까진 없었던 듯

 

이때 아래와 같은 메시지가 뜰 수 있음

Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

왜 해당 merge가 필요한지 내용을 남기라는 건데, vi 편집기를 사용하여 입력해야 하기 때문에 일반적인 입력 방법으로는 입력 불가

  1. `i` 입력하여 글자 입력 모드로 전환
  2. merge 이유에 대한 내용 작성
  3. `esc`키 눌러 입력 모드 벗어나기
  4. `:wq` 입력하여 저장 및 종료
  5. `enter`

참고

https://jobc.tistory.com/177

 

git push, pull (fatal: refusing to merge unrelated histories) 에러

원격 저장소를 remote로 설정하고 바로 push를 하면 몇가지 오류가 발생할 수도 있다.예를 들어 아래와 같은 오류 메시지이다.12 ! [rejected] master -> master (non-fast-forward)error: failed to push some refs to 'https:

jobc.tistory.com

https://stackoverflow.com/questions/19085807/please-enter-a-commit-message-to-explain-why-this-merge-is-necessary-especially

 

Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic b

I am using Git. I did a pull from a remote repo and got an error message: Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a

stackoverflow.com

 

저작자표시 (새창열림)

'트러블슈팅' 카테고리의 다른 글

[트러블슈팅/SpringBoot] 415 오류: Content-Type 'application/octet-stream' is not supported  (0) 2026.05.19
[트러블슈팅/SpringBoot] WebMvcTest로 Controller 테스트 시 JwtUtil 인식 안 됨  (1) 2026.03.11
[트러블슈팅/SpringBoot] Builder 필드 초기값 누락  (0) 2026.01.22
[트러블슈팅/SpringBoot] Error creating bean with name 'entityManagerFactory' defined in class path resource  (0) 2024.12.05
[트러블슈팅/Java] incompatible types: char cannot be converted to string  (0) 2024.07.04
'트러블슈팅' 카테고리의 다른 글
  • [트러블슈팅/SpringBoot] WebMvcTest로 Controller 테스트 시 JwtUtil 인식 안 됨
  • [트러블슈팅/SpringBoot] Builder 필드 초기값 누락
  • [트러블슈팅/SpringBoot] Error creating bean with name 'entityManagerFactory' defined in class path resource
  • [트러블슈팅/Java] incompatible types: char cannot be converted to string
naahy
naahy
  • naahy
    종합장
    naahy
  • 전체
    오늘
    어제
    • 분류 전체보기
      • Java
      • SpringBoot
      • Git
      • 트러블슈팅
      • Vue.js
      • Kotlin
      • Node.js
      • 코딩테스트
        • 백준
        • 프로그래머스
      • 스터디
        • CS
        • 알고리즘
      • -
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 인기 글

  • 태그

    코틀린
    SpringBoot
    node.js
    cs
    트러블슈팅
    브루트포스
    Kotlin
    React
    백트래킹
    Java
    프로그래머스
    자바
    투포인터
    mongodb
    Nexacro
    API
    백준
    bfs
    이분탐색
    github
  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
naahy
[트러블슈팅/GitHub] 원격저장소 - 로컬저장소 기록(history) 병합
상단으로

티스토리툴바