git 오류발생!☹️

sh.j225·2023년 7월 18일
0
https://kr.freepik.com/free-vector/computer-user-human-character-and-program-windows_17257364.htm#query=error%20finding&position=49&from_view=keyword&track=ais(이미지출처)

 hooni@jangsihun-ui-MacBookAir SE7EN_11 % git push origin main
To github.com:sihunjang225/SE7EN_11.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:sihunjang225/SE7EN_11.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.

해당 에러는 git으로 로컬에서 원격 저장소로 코드를 푸시하려고 할 때 발생 된 것으로 보인다. 원격 저장소에 이미 변경 사항이 있고 로컬에는 없는 경우 발생하는데, 이는 다른 저장소에서 동일한 브랜치에 푸시하면 발생할 수 있다.

이러한 경우 로컬 변경 사항을 원격 변경 사항과 통합하여 먼저 로컬 브랜치를 업데이트해야 한다.

이를 위해 git pull 명령어를 사용하여 명령어를 실행하기 전, 변경 사항이 충돌하지 않도록 현재 작업 중인 파일들을 저장하거나 커밋하면된다.😤

아래는 원격 브랜치인 main으로 풀(pull)을 수행하는 방법이다

hooni@jangsihun-ui-MacBookAir SE7EN_11 % git pull origin main

이 명령을 실행하면 원격 저장소의 main 브랜치에서 변경 사항을 가져와 로컬 브랜치에 병합(merge)할 수 있다. 변경 사항이 없거나 자동으로 병합할 수 있으면 병합이 완료된다. 그러나 변경 사항이 충돌하는 경우 직접 충돌을 해결해야 한다.

충돌을 해결한 후 변경 사항을 다시 커밋할 수 있다. 그리고 이제 원격 저장소로 푸시하면 된다.

hooni@jangsihun-ui-MacBookAir SE7EN_11 % git push origin main

변경 사항이 원격 저장소로 정상적으로 푸시되었다!

1개의 댓글

comment-user-thumbnail
2023년 7월 18일

좋은 글 잘 읽었습니다, 감사합니다.

답글 달기