Create empty branch on GitHub

前端 未结 4 803
闹比i
闹比i 2020-12-22 16:31

I want to create a new GitHub branch, called release.

This branch needs to be empty! However, there is an existing branch with x commits

4条回答
  •  礼貌的吻别
    2020-12-22 16:41

    --orphan is good for creating an empty branch locally, however, in order to push it or interact with other branches, you will need a commit.

    Creating a new commit on an orphan branch is not a good idea because you won't be able to interact with other branches. I.e.

    git checkout --orphan test
    git commit --allow-empty -m "init test branch"
    git merge master
    fatal: refusing to merge unrelated histories
    

    Instead, you should prefer creating a new branch from the first commit of master. If the commit is not empty you can add an empty commit before the first one, as explained by @houtanb.

提交回复
热议问题