git remote add origin 깃허브저장소주소.git
git branch -M main
git push -u origin main
나는 branch가 main으로 설정되어 있으므로 master였던 브런치를 main으로 바꾸어주는 코드도 추가했다(두 번째 줄git branch -M main
). 확인해보고 원래 자신의 브런치대로 설정되어 있는 경우에는 안바꿔도 됨.
참고 링크:
https://www.atlassian.com/git/tutorials/saving-changes/gitignore
.gitignore 파일 생성 -> 제외시킬 파일 이름 작성
git add -A
git commit -m "추가사항"
git push origin main
git push 명령어를 실행하여 내 로컬 레포지토리의 내용을 github 원격 레포지토리로 업로드(push)하려 했는데 되지 않았다.
에러 로그 메시지
Updates were rejected because the remote contains work that you do not have locally.
에러의 이유
github에서 레포지토리를 생성할 때, README.md 파일을 생성했기 때문이다.
해결
git pull 명렁어로 github의 원격 레포지토리를 내 로컬로 불러와서(fetch) 합친다(merge.)
그리고 git push 명령어로 다시 원격 레포지토리에 업로드한다.
(출처: https://waaan.tistory.com/13)
또는 git push -u origin +main
으로 해결 가능 (readme를 없앤다.)