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

JY·2022년 4월 21일
3

Git, GitHub

목록 보기
1/3
post-thumbnail

❓ 에러 발생 원인


Git Bash를 이용해서 GitHub에 TIL을 올리기 시작한지 3일차...
슬슬 익숙해졌다고 생각했고 어제랑 별다를 거 없이 파일 생성, 내용 작성, 커밋까지 완료 후 push를 했지만.. 에러 메시지가 나왔다!!

$ 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.

분명 어제와 똑같이 했는데 빨간 글씨로 reject가 뜬 걸 보고 당황했다.. 뭔가 잘못해서 저장소 날려먹는 게 아닌가 겁이 났다.😵‍💫

👉 찾아본 결과 로컬 저장소와 원격 저장소의 상태가 달라서 그렇다고 한다!
대체 뭐가 다를까 생각해 봤는데 어제 Git Bash로 push까지 마친 후, 바보같이 Git Bash에서는 이모지를 쓸 수 없는 줄 알고.. 깃허브 웹페이지(원격 저장소)에서 수정해버린 것이다... 그러니 상태가 다를 수밖에...ㅎㅎ


💡 해결법


원격 저장소와 로컬 저장소의 상태가 달라서 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개의 댓글