삽질의 현장/- GIT

[삽잡이 :: GIT] 어랏 push가 왜 안되지

shovelman 2017. 9. 10. 07:38



멋대로 샤샤샥 커밋을 하다가... 갑자기!

push가 안된다면 어떻게 할 것인가...


너님이 뭘 잘못한지 스스로 돌아봐봐....



장난이구요...

원격 저장소에서 pull을 땡겨오지 않을 때면 아래와 같은 문제로 push가 되지 않을 수 있습니다.


$ git push --set-upstream origin master

To https://github.com/안알랴줌/foo.git

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


error: failed to push some refs to 'https://github.com/안알랴줌/foo.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.


왜냐하면, 열심히 작업하고 딱~ 올리려 했는데,

이미 원격 저장소에는 내가 작업한 코드가 업데이트 되어있다면?


나의 것으로 덮어버리자. 


라고 생각하면 안됩니다.


원격지에서 최신 내용을 먼저 받아오고 (pull), 제가 작업한 내용과 합쳐서 올려야합니다.


$ git pull origin master


원격지 저장소에 내용과 저의 코드가 겹치는 부분 없이 깔끔하게 병합(merge)이 될 수도 있고,

같은 부분을 고쳤다던지 한다면, 충돌(conflict)이 발생할 수 있다.


이때는, 머리를 잘 굴려서 어떤 코드를 이식할지... 생각 잘해야합니다. 후후..


아무튼... 마지막 방법으로 강제로 그냥 때려박는 경우가 있는데,

이 방법은 좋지 않은 것 같습니다.

물론, 경우에 따라 독이되고 약이 될 수 있는 상황들은 넘쳐나겠지만...


위험하니까 함부로 쓰지 마세요! (참고)

$ git pull origin master --allow-unrelated-histories 



그리하여 잘 처리해주시면~!

 $ git push --set-upstream origin master

Counting objects: 7, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (7/7), 605 bytes | 605.00 KiB/s, done.

Total 7 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1), done.

To https://github.com/안알랴줌/foo.git

   1de4d42..d7ac614  master -> master

Branch master set up to track remote branch master from origin.


깔끔하게 push가 됩니다~!


와~~~ 


'삽질의 현장 > - GIT' 카테고리의 다른 글

[삽잡이::GIT] LF will be replaced by CRLF  (0) 2017.09.09