Git 원격저장소 등록하기

용씨·2023년 1월 30일
0

Github에서 새로운 레포지토리 생성 후, 로컬 폴더에 있는 프로젝트를 Git에 push 해보겠습니다.

cd [폴더]
git init --initial-branch=main
git remote add origin [git 주소]
git add .
git commit -m "Initial commit"
git push -u origin main
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 push를 해줍니다. main은 브런치명입니다.

git pull origin main --allow-unrelated-histories
git push origin main

--allow-unrelated-histories란 git에서는 서로 관련 기록이 없는 이질적인 두 프로젝트를 병합할 때 기본적으로 거부하는데, 이것을 허용해 주는 옵션입니다.

그 후 git push를 다시 하니까 다음과 같은 오류가 떴습니다.

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

원격저장소 이름을 명확하게 지정해줍니다.

 git push --set-upstream origin main

위 방법 외에도 참고할 내용을 이미지로 첨부합니다.

profile
아침형 인간이 목표

0개의 댓글