굳이 develop, main 브랜치에서 따오지 않아도 되는 브랜치를 만들 때가 있는데, 그럴땐 orphan branch로 만들면 좋습니다
git switch --orphan <new branch>
switch를 사용하면 됩니다 (git 2.27 버전부터 사용가능)
checkout과의 다른점이라고 하면 로컬 파일을 남기지 않습니다
git checkout --orphan <new branch>
git rm -rf .
checkout을 쓴다면 이런식으로 씁니다
주의사항
~~~~ and ~~~~ are entirely different commit histories.
이렇게 만든 브랜치에서 그냥 브랜치로 PR을 만들려고 하면 깃허브에서 거부합니다
$ git checkout develop
$ git merge empty-start-branch
fatal: refusing to merge unrelated histories
로컬에서 git으로 머지를 해도 마찬가지인데요, 애초에 시작점이 다른 두 브랜치를 머지할 일이 없으니 실수 방지를 위해 막아놓은겁니다
git 2.9부터 이렇게 동작하도록 바뀌었다고 합니다
$ git merge empty-start-branch --allow-unrelated-histories
원한다면 --allow-unrelated-histories 옵션을 사용해 강제로 머지할 수 있습니다
참고
반응형
'Software > development' 카테고리의 다른 글
[git] 빈 브랜치 만들기 (orphan branch) (0) | 2022.08.03 |
---|---|
postman 대체재, insomnia (0) | 2022.07.24 |
[VirtualBox] m1 관련 문제 (0) | 2022.07.22 |
[Jetbrains] toolbox shell script가 생성되지 않을 때 해결방법 (0) | 2022.06.18 |
[powerlevel10k] alias 띄우기 (0) | 2022.02.27 |
Octotree(옥토트리) forbidden 해결방법 (0) | 2022.01.19 |