Error

[Git] error: failed to push some refs to

dltjdn 2022. 4. 22. 17:28

Error

error: failed to push some refs to 'https://github.com/gitId/repositoryName.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에서 레포지토리를 만들 때 아래와 같이 Add a README  file을 체크했다

그리고 로컬에서 git init → git add → git commit 하고

git remote add origin [리포지토리 주소] 하여 원격 repository를 add 한 후

git push origin main 을 하였는데 위와 같은 오류가 발생하였다

 

 

 

원인

Updates were rejected because the remote contains work that you do not have locally.

→ github에서 레포지토리를 만들 때, README.md 파일을 같이 생성했기 때문이다




해결방안

1. github 레포지토리에서 README.md 파일을 삭제한 후  다시 push 한다

 

2. git pull으로 github 저장 내용을 불러와 합친 후 다시 push 한다

git pull origin main
git push origin main

 

해결 방안 1,2 중 어느 것을 이용하든 아래와 같이 오류가 해결된다