개인공부/TIL(Today I Learned)

TIL 63일차_git: local - remote 연결

soon327 2021. 3. 22. 02:00

local repository와 이미 있는 remote repository 연결하기

로컬에 이미 파일을 만들었고,
remote repository도 따로 만들었을 때 이둘을 연결하는 법!

  1. 일단 먼저 remote add해준다.
    git remote add origin 레포링크

  2. pull 해주기

remote 연결했으니 이제 push를 하기전에 pull로 merge해줘야겠지??
그러나 오류가발생한다.

fatal: refusing to merge unrelated histories

이건 해당 remote repo와 local repo가 아무런 관련이 없기때문에 생기는 에러이다.
따라서 이를 억지로 pull해줘야하며, 명령어는 다음과 같다.
git pull origin main --allow-unrelated-histories

이렇게하면 merge가 되고, 이제 remote에 git을 올릴 수 있다.

  1. branch main

내경우에는
remote default branch가 main으로 설정되어있고,
local default branch는 master로 설정되어 있었다.

작년 6월, Go 언어가 인종차별적 요소나 주종 관계의 의미를 담고 있는
whitelist/blacklist와 master/slave라는 용어를 프로젝트에서 제거하기로 결정하면서,
업계 전반에 이런 부분을 제거하는 움직임이 일어났다고 한다.
이에맞춰, git에서도 default branch를 master에서 main으로 변경했다.

따라서
remote에 넘겨주기 전에,
local repository의 master branch를 main branch로 변경해줘야 한다.
git branch -m master main

또는!!
매번 이렇게 변경하기 번거롭다면
Git을 2.28.0 버전 이상으로 업데이트하고,
git config --global init.defaultBranch main 을 입력하여
local의 default branch를 설정해주자!

'개인공부 > TIL(Today I Learned)' 카테고리의 다른 글

TIL 65일차_npm vs npx  (0) 2021.03.24
TIL 64일차_Express.js : 라우팅  (0) 2021.03.23
TIL 62일차_Git: .gitignore  (0) 2021.03.21
TIL 61일차_ChatterBox  (0) 2021.03.20
TIL 60일차_ Browser Security: XSS  (0) 2021.03.19