본문 바로가기
DevOps/Git

[해결 방법] error: failed to push some refs to 'https://github.com/'

by HJ0216 2023. 1. 22.

발생 Error

Git Bash에서 다음 명령어를 입력할 경우,

$ git push -u origin main
To https://github.com/HJ0216/TIL.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/HJ0216/TIL.git'

! [rejected]        main -> main (fetch first)
⭐ error: failed to push some refs to 'https://github.com/HJ0216/TIL.git'

Error 발생

 

 

Error 원인

원격 저장소의 main branch에 저장되어있는 내용과 로컬 저장소의 내용이 일치하지 않아 발생

 

 

해결 방법

원격 저장소 내용을 로컬 저장소에 먼저 pull 시킴

$ git pull origin main
remote: Enumerating objects: 247, done.
remote: Counting objects: 100% (247/247), done.
remote: Compressing objects: 100% (187/187), done.
remote: Total 247 (delta 73), reused 157 (delta 38), pack-reused 0
Receiving objects: 100% (247/247), 59.49 KiB | 378.00 KiB/s, done.
Resolving deltas: 100% (73/73), done.
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main
fatal: refusing to merge unrelated histories

 

 

⚠️ 추가 문제: fatal: refusing to merge unrelated histories Error 발생

(참조: [해결 방법] fatal: refusing to merge unrelated histories)

 

 

 

참고 자료

📑[GitHub] Repository에 'main' branch로 push 하기