git push error 모음집(1)

춤추는 병따개·2023년 3월 27일
0

git으로 프로젝트를 push하는데 에러가 생겼다.


failed to push some refs to~,Updates were rejected because the remote contains work that you do not have locally 에러

! [rejected]        master -> dev (fetch first)
error: failed to push some refs to 'https://myusername@bitbucket.org/repo_user/repo_name.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.

깃허브에 로컬 프로젝트를 push하는 도중 아래와 같은 에러가 발생했다. 원인은 같은 레퍼지스토리에 push를 줬다는게 원인이라고 한다.

새 래퍼지토리를 만들때 README.md를 직접 생성했는데, 그게 내 로컬에는 없는 commit이라 그런듯 하다.

방법1) 새로운 명령어 입력 (force..? 인듯하다)

git push -f origin master

하지만 나의 경우, 방법으로는 해결이 안되었기에 다른 방법을 시도했다.

방법2) 원격 저장소에 커밋된 (README.md)파일을 pull해보자. 그 이후 다시 push

git pull {원격저장소별칭 보통 origin이라고 함} master
git push origin master

되는듯 하다가 또 에러가 떴다.


fatal: couldn't find remote ref master 에러

잠깐 기뻐하다 또다시 뜬 에러 문구.
래퍼지토리 브랜치 이름이 다를때 뜨는 문구라고 해 확인해본 결과

main인데 master로 push해서 문제인듯 하다.
편집 아이콘을 눌러 브랜치 이름을 master로 바꾸면 되었다.

....이렇게 했으면 좋았으련만 github에서 직접 수정말고 git으로 하고싶다는 욕심때문에 되돌릴 수 없는 실수를 하는데...

🤭git branch -M master 명령어를 주고 다시 순서대로 하면 되겠지?=> 안됨


fatal: Need to specify how to reconcile divergent branches. 에러

엄청나게 긴 오류가 떴다.

hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

궁금한 것이 git pull을 할 때 Pull = fetch 패치 + merge 병합이라고 알고 있는데 최신 버전에서는 어떤 병합 전략을 사용할지 따로 지정하는 걸까?

일단 오류를 빨리 해결하고 싶어 힌트가 준 해결책 3가지 중 첫번째 merge로 진행.
해결방법 3)git config pull.rebase false

참고
인터넷에 찾아보니 전역으로 지정해주고 싶다면 git config --global pull.rebase false를 해주면 된다. 지정하고 나면 새로운 브랜치가 있을 경우 3-way-merge를 해주고 없다면 fast-forward로 브랜치를 병합해준다고 한다.


Updates were rejected because the tip of your current branch is behind its remote.. 에러

이후에 새로 등장한 에러, 이것도 github repository를 생성할 때 readme.md를 생성했기 때문에 github에 push 하려고 할때 발생하는 오류라고 한다. 결국 처음의 문제가 아직 해결되지 않고 있다는 것을 파악했다.

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에서 처리 되지 않도록 에러를 띄우는 것이라고 하는데,
근본적인 원인을 찾아 해결할 수도 있지만 임시방편으로 “+”를 이용하여 해결이 가능하다고 한다.

앞선 방법들을 반복하다 해결이 되지않아 강제로 push하는 방법을 찾았다.

해결방법 4)git push -u origin +master
해결방법 5)git push -u origin +main
((둘 중에 하나라도 되라))


이것으로 해결된듯 하다.
github에 바로 반영이 되지는 않아 식겁했지만 시간이 지나서 보니 잘 들어와있었다. ^^
그 사이에 안되는줄 알고 포기하고 새 래퍼지토리를 생성하고 다시 Push를 하고있었는데, 방법4)로 해결된게 아니라 이것 떄문에 push가 된것이고 새 래퍼지토리에 안들어가고 기존 래퍼지토리로 파일이 들어갔을수도 있다...이렇게 해결된거라면 내가 아직 git사용에 상당히 미숙한 것으로 생각된다...

그런데 실제로 파일이 유실된 것인지 따른 문제가 발생했다.

github에 프로젝트를 올리기만 하면 항상 css 파일이 연결이 되지 않는다.

profile
FE 개발 공부 중

0개의 댓글