본문 바로가기
Study/error 삽질

[GitHub] Push 에러 해결하기 (error: failed to push some refs to)

by 코딩여걸 2021. 7. 5.
728x90

📝 github에 commit을 하다가  git push origin master 를 입력했는데 갑자기 에러가 발생했다.

< Error Message >

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/jiyeong1004/JAVA200_Intermediate.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.

 

< 문제 (Error) 발생 원인 >

error: failed to push some refs to 발생 이유는

git의 원격 저장소와 현재 local 저장소가 동기화되어있지 않기 때문이다.

데이터 유실 등의 문제가 있을 수 있는 부분이 존재한다는 뜻이다.

git에서 처리되지 않도록 막아뒀기 때문에 에러가 발생한다.

< 해결 방법 >

- 동기화를 시켜주면 간단하게 해결된다.

 

1. git pull origin master (※ 이건 개인마다 명령이 다를 수 있음)

 git pull origin master  을 해준 후

원래 추가하는 방법대로 push를 해주면 된다.

 

2. 데이터 유실 등 위험을 감수하고 git에 강제로 push 한다.

- 강제 push 방법은 "+"를 붙여주면 된다.

 

기존 명령 :  git push origin master 

강제 명령 :  git push origin +master 

 

강제로 push를 할 경우 repository의 모든 작업물을 다 날릴 수 있다.

강제 명령어 사용지양하고

문제가 발생한 부분을 수정하거나 동기화하는 방식지향하는 것이 좋다.

(참고 : https://aonee.tistory.com/14)

< 해결 >

성공적으로 push 된 것을 볼 수 있다.

728x90

댓글