git push error

2022. 2. 25. 11:32CM/Github

반응형
반응형

git에 push를 하려는데 아래와 같은 오류 발생!
rejected!! 대~충 읽어보니 git push전에 git pull을 하라고 한다

git push -u origin master
To https://github.com/pthahaha/rest-api-study.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/pthahaha/rest-api-study.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

그래서 git pull을 했더니 아래와 같이 There is no tracking information for the current branch. 라 카면서 디테일하게 git pull을 해달라고 한다. 음..간곡히 부탁하는거 같으니 디테일하게 명령어를 때려주자!

git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

git branch --set-upstream-to=origin/master master

위처럼 가이드대로 명령어를 때려주면! Branch 'master'가 set up되었다고 한다 remote branch master인 origin이랑!
origin 요녀석은 git remote -v를 해주면 명명을 확인할 수가 있다.

git remote -v

이제 pull을 해서 어떤 녀석땜에 push를 못했는지 확인해보자!

 git pull
fatal: refusing to merge unrelated histories

거절당했다...이유는 merge를 하는데 unrelated histories가 있다는 것이다.
원격지에 README.md파일을 생성해서 로컬과 원격지의 내용이 틀려서이다.

생각해보니..
1. 로컬에 소스를 짜고 git init후 remote Repository와 연결을 한다고 했을 때
2. github에서 아무내용이 없는 Repository를 만들고 push를 했어야했다.



이제 이렇게 되면 강제성을 부여해야한다.(pull이든 push이든)
역시..README.md 파일이 범인이였다..

​아래와 같이 README.md파일을 pull로 로컬에 가져왔다!

이제 대망의..push!!

 git push -u origin
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 12 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (30/30), 60.00 KiB | 12.00 MiB/s, done.
Total 30 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/pthahaha/rest-api-study.git
   74dfa15..dd5d7a2  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

github에 가서 확인해보니 잘 push되었음을 알수 있다!

끝~

반응형