Git

git - pull하지 않고 작업 후 push 시에 해결방법

js-kkk 2025. 3. 13. 12:42

야구 골든글러브 수상을 예측하는 모델을 만드는 미니 프로젝트를 하던 중에 git 문제가 발생했다.

문제점

Playdata@DESKTOP-O325F7G MINGW64 /c/encore_skn11/project_final (main)
$ git push origin main
To https://github.com/encore-SKN11/EDA-1Team.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/encore-SKN11/EDA-1Team.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

작업 후 push를 하던 중 에러가 발생했다.

 

오류 메시지를 보면 리모트 저장소(GitHub)에 있는 최신 변경 사항을 가져오지 않고 git push를 시도했기 때문에 업데이트가 거부(rejected) 되었다. 

 

 

 

 

해결방법

 

 

git pull origin main --rebase

 

rebase 옵션을 사용하면 로컬 변경 사항을 최신 원격 변경 사항 위에 적용해 깔끔하게 커밋 히스토리를 유지할 수 있다.

'Git' 카테고리의 다른 글

git 기본 설정 + 원격 저장소에 push  (0) 2025.02.18