[Git Error] failed to push some refs to ... 해결하기

지환·2023년 10월 30일
0

깃-오류

목록 보기
4/7
post-thumbnail
$ git push origin main
To https://github.com/jytrack64/TIL.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/jytrack64/TIL.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

원인 : 찾아본 결과 로컬 저장소와 원격 저장소의 상태가 달라서


해결법

원격 저장소와 로컬 저장소의 상태가 달라서 push가 되지 않는 것이므로 먼저 pull을 하고, push를 하면 된다!

$ git pull

그리고 pull을 하면 브랜치를 merge하면서 commit 메시지도 자동으로 만들어 주는데 당황하지 않고 그냥 저장하고 나가면 된다.

$ git pull
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 12 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), 2.91 KiB | 38.00 KiB/s, done.
From https://github.com/jytrack64/TIL
   e85409f..9ca8b8c  main       -> origin/main
Merge made by the 'ort' strategy.
 2022/202204/20220420/README.md | 10 +++++++---
 README.md                      | 10 ++++++----
 2 files changed, 13 insertions(+), 7 deletions(-)

성공적으로 pull을 마친 후, 다시 push를 하면 잘된다!!

$ git push origin main
Enumerating objects: 16, done.
Counting objects: 100% (16/16), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 2.31 KiB | 591.00 KiB/s, done.
Total 10 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/jytrack64/TIL.git
   9ca8b8c..1e4233a  main -> main
profile
아는만큼보인다.

0개의 댓글