프로젝트를 깃에 올리려는데 답답해서 쓰는 글.
$ git add .
$ git commit -m "Write something"
$ git push
이거 말고는 정말 하나도 기억에 남아있지를 않았다. 그나마도 세 번째 명령어는 틀렸다. 맙소사.
일단 깃헙에 뭘 올리려면 로컬과 레포가 내용은 달라도 같은 파일을 가지고 있어야 한다. 로컬에 없는 파일이 레포에 있다?
! [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 태그는 없어도 되는 것 같다.