Computer Engineering/github

[github] 로컬 프로젝트를 github 저장소에 올리기

soohey 2022. 5. 18. 17:27
>> git config --global user.name "사용자회원이름"
>> git config --global user.email "사용자이메일"

나의 깃허브 회원정보를 입력하는 명령어입니다.

 

>> git init
>> git remote add origin 깃허브주소

git remote를 통해 프로젝트를 저장하고 싶은 주소를 연결해줍니다.

 

>> git add .
>> git commit -m "first commit"
>> git pull origin main --allow-unrelated-histories
>> git push origin main

git commit을 통해 프로젝트를 올릴 수 있습니다.

push 전에는 pull을 통해 프로젝트를 merge하는 과정이 필요합니다.

 

--allow-unrelated-histories 옵션은 왜 필요할까요?

git push를 입력했을 경우 아래와 같은 에러를 발견할 수도 있습니다.

PS C:\hello-spring> git push origin main
To https://github.com/suhyeon10/hello-spring.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/suhyeon10/hello-spring.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.

git pull을 하라고 해서 명령어를 실행해도 pull이 안될 경우 --allow-unrelated-histories 옵션을 통해 해결할 수 있습니다.

 

git pull origin 브런치명 --allow-unrelated-histories

이 명령 옵션은 이미 존재하는 두 프로젝트의 기록을 저장하는 상황에 사용합니다.

깃 저장소와 로컬저장소의 프로젝트는 서로 관련없는 이질적인 각각의 프로젝트이므로 병합할 때 기본적으로 거부를 하게 되는데, 이것을 허용해주는 옵션입니다.

 

 

https://gdtbgl93.tistory.com/63