GitHub
[GitHub] git push 오류 (error: failed to push some refs to ...)
코드비버
2025. 5. 15. 18:41
GitHub에 업데이트된 소스파일을 push 하려는데 'error: failed to push some refs to <깃헙주소>' 오류가 발생했다.
$ git push
To https://github.com/duski96/portfolio.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/duski96/portfolio.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.
처음엔 뭐라고 하는건지 이해가 안됐는데, 결론적으로 GitHub 저장소의 Readme.md 파일을 업데이트 하면서 로컬 폴더의 소스와 버전이 맞지 않아서 그렇다고 한다.
따라서 git pull 명령어를 통해 로컬과 GitHub의 소스파일을 동일한 버전으로 맞춰준 다음 git push 명령을 진행하면 된다.
git pull 명령 실행
git pull 명령을 실행하면 다음과 같은 경고(E325)가 나오는데, 병합 과정에서 임시 파일을 발견했다는 경고문이다.
뭔가 거창하게 적혀있지만 그냥 q 명령어로 빠져나오면 된다.
* git pull 명령어를 실행하면 지금까지 작업한거 날아가는게 아닌지 걱정했는데, 다행히 잘 남아있었다.
E325: ATTENTION
Found a swap file by the name "~/Desktop/PORTFOLIO/.git/.MERGE_MSG.swp"
owned by: J dated: Mon Feb 17 14:04:59 2025
file name: ~J/Desktop/PORTFOLIO/.git/MERGE_MSG
modified: YES
user name: J host name: DESKTOP-3CPNVNU
process ID: 922
While opening file "/c/Users/J/Desktop/PORTFOLIO/.git/MERGE_MSG"
dated: Thu May 15 18:24:04 2025
NEWER than swap file!
(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /c/Users/J/Desktop/PORTFOLIO/.git/MERGE_MSG"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/c/Users/J/Desktop/PORTFOLIO/.git/.MERGE_MSG.swp"
to avoid this message.
Swap file "~/Desktop/PORTFOLIO/.git/.MERGE_MSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
git commit, git push 명령 실행
이후 git commit 명령을 통해 실행된 병합 commit을 남기고 git push 하면 정상적으로 업데이트된다.