Git 에러들

박지현·2023년 2월 16일
0

GitHub

목록 보기
4/7
post-thumbnail

push가 안되는 경우 (fatal: refusing to merge unrelated histories)

push 전에 먼저 pull을 해서 프로젝트를 병합해 주어야 한다.

 refusing to merge unrelated histories

pull 명령 실행시 이런 문구와 함께 진행되지 않는다면, 다음의 명령으로 실행한다.

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

git pull origin main --allow-unrelated-histories

--allow-unrelated-histories 이 명령 옵션은 이미 존재하는 두 프로젝트의 기록(history)을 저장하는 드문 상황에 사용된다고 한다. 즉, git에서는 서로 관련 기록이 없는 이질적인 두 프로젝트를 병합할 때 기본적으로 거부하는데, 이것을 허용해 주는 것이다.

pull이 안되는경우 1

* [new branch]      master     -> origin/master 
There is no tracking information for the current branch. 
Please specify which branch you want to merge with. 
See git-pull(1) for details.      

    git pull <remote> <branch>  

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

현재 branch에 대한 추적 정보가 없다. 병합할 branch를 지정해라 라는 메시지이다.

-u--set-upstream-to 옵션 줘서 로컬 master가 origin/master를 추적하게끔 해줍니다.

git branch --set-upstream-to=origin/master master

push

Solution1. 터미널에서 master에서 main으로 바꾸기

branch 이름을 터미널에서 master을 main으로 바꾸기 위해서 아래의 명령어를 쓰면 된다.

방법

해당 local refence 터미널에서 아래 두 가지 중 한 명령어를 실행한다. 둘 다 같은 의미이다.

git branch -m master main
or

git config --global init.defaultBranch main

default banch를 master > main으로 변경함으로써 앞으로 git push 할 때 아래와 같이 입력해도 잘 될 것이다.

git push origin main

Solution2.local branch name은 유지한 채로 원격 브랜치에 넣는 법

soution1의 방법이 싫다면(싫을 이유는 없지만?) 혹은 안된다면, 아래와 같은 명령어로 push 해줄 수도 있다.

git push origin HEAD:main

Solution3.git 생성 시 브랜치 네임 생성

애초에 git을 생성할 때 main으로 생성하는 방법이 있다.

git init을 생성할 때 아래의 둘 중 하나의 방법으로 생성하면 브랜치 이름이 main으로 지정이 된다.

git init --initial-branch=main

or

git init -b main
profile
프론트엔드가 목표!

0개의 댓글