굳이 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' 카테고리의 다른 글
[Jenkins] jnlp port:5000 is not reachable (2) | 2022.09.01 |
---|---|
[PyCharm] redis.asyncio를 찾지 못하는 현상 해결방법 (0) | 2022.08.31 |
postman 대체재, insomnia (0) | 2022.07.24 |
[VirtualBox] m1/m2 설치 방법 (0) | 2022.07.22 |
[Jetbrains] toolbox shell script가 생성되지 않을 때 해결방법 (0) | 2022.06.18 |