[git error] fatal: No configured push destination.

장우솔·2022년 1월 5일
0

git

목록 보기
1/3

push 해주려는데 오류떴당,,,

fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using 

후에 이렇게 떴당,,

git remote add <name> <url>

and then push using the remote name

git push <name>

그래서 그대로 git remote add origin http어쩌고~시도했는데
또 오류뜸,,,

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

라고 뜨길래 그대로 시도했더니 또 오류뜸!

 ! [rejected]        main -> main (fetch first)
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.

힌트에 pull하라길래 단순히 git pull 하고 다시 push 했더니 똑같은 오류

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

으악 어쩌라는거지 뭐가 문제였을까 하고 구글링 하던 중 원격 저장소 이름을 언급해주지 않아서 발생했다는 것을 알게 되었고, 따라서 git remote -v 로 현재 저장된 원격 저장소 찾은 뒤 원격저장소 명시하면 해결된다했다.

git remote -v
git push origin main

를 실행했는데 야호! 또 오류떴다 ㅎㅎㅎㅎㅎ

! [rejected]        main -> main (non-fast-forward)

그래서 이건 뭔데요,,,,,,, 그래서 구글링 하던 중에

강제 push 할 수 있다는 코드를 보고 git push -u origin +main로 강제 푸쉬 해버림 ㅎㅎㅎㅎ 그 결과

전에 올렸던 거 다 사라졌다!


그래서 어쩔 수 없이 전에 pull받은 폴더에서 파일을 다시 복사한 뒤 지금 깃이 들어있는 파일에 붙여넣기 해주고 다시 add, commit, push 해줬다,,,,,,pull실수인가,,같은 branch를 사용해서 문제인건가,, 개념을 정확히 몰라서 이런 결과가 발생한 것 같다. 나같은 실수하지 마시길 바라면서,,,,

원인으로는
깃헙에 생성된 원격 저장소와 로컬에 생성된 저장소 간 공통분모가 없는 상태에서 병합하려는 시도로 인해 발생.
기본적으로 관련 없는 두 저장소를 병합하는 것은 안되도록 설정되어 있다.

깃허브 repository에는 파일이 삭제됐지만 기존에 남아있는(Pull Request)파일에는 해당 파일이 남아있어서 충돌이 되는게 원인이 된거같다.

깃 사용 중 해결방안

새로운 원격저장소를 만들고 로컬 저장소와 연동할 때 git pull 말고 git pull origin main명령어를 사용해야 한다.
빠뜨렸을 때, git pull origin main --allowed-unrelated-histories 명령어를 통해 원격저장소와 로컬 저장소 병합을 허용한다.

처음 push할 때 에러 해결방안

브랜치 명령 앞에 +를 추가해서 push 한다.
git push origin +main

혹은
git branch -M main 하고,
git push -u origin main 명령어 입력하니까 수행함!

profile
공부한 것들을 정리하는 블로그

0개의 댓글