Jul.20.21

iissaacc·2021년 7월 20일
0

TIL

목록 보기
1/10

Prologue

프로젝트를 깃에 올리려는데 답답해서 쓰는 글.

$ git add .
$ git commit -m "Write something"
$ git push

이거 말고는 정말 하나도 기억에 남아있지를 않았다. 그나마도 세 번째 명령어는 틀렸다. 맙소사.

if len(local) != len(repo): raise Exception

일단 깃헙에 뭘 올리려면 로컬과 레포가 내용은 달라도 같은 파일을 가지고 있어야 한다. 로컬에 없는 파일이 레포에 있다?

 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/username/repository.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.

그러면 이런 오류를 봐야지. 다행인 점은 깃은 적어도 오류가 왜 났고 뭐해야 하는지 귀띔이라도 해준다. 일단 시키는대로 해보자.

$ git pull origin main

이렇게 하면 로컬에 없는 파일을 레포에서 받아와서 콘솔에 찍어준다.

Merge made by the 'recursive' strategy.
 README.md       | 29 +++++++++++++++++++++++++++++
 project/README.md | 17 +++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 project/README.md

그러면 len(local) == len(repo)가 되면서 위 조건문을 넘을 수 있다. 이제 진짜 레포에 올릴 준비가 됐다.

$ git push -u origin main

제대로된 push 명령어는 이렇게 생겼다. -u 태그는 없어도 되는 것 같다.

Epilogue

  1. 레포를 만들때 .md 파일이 만들어지게 했는데 이것 때문에 오류가 날 줄은 생각도 못 했다.
  2. 사실 이러고 나서도 프로젝트를 올리지 못했다.

0개의 댓글