Git 从现有存储库创建一个空分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32559168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:23:06  来源:igfitidea点击:

Git create a empty branch from existing repository

gitbranch

提问by Brajesh Pant

I have a git repository which has many branches my requirement is to create a new empty branch so that its independent of the earlier branches.

我有一个 git 存储库,它有很多分支,我的要求是创建一个新的空分支,使其独立于较早的分支。

回答by Samuel Dauzon

That's not a good practice, but if you want really start with a new branch without relation to master you must use --orphanargument of checkout :

这不是一个好习惯,但如果你真的想从一个与 master无关的新分支开始,你必须使用--orphan参数 checkout :

git checkout --orphan version2
# and remove your project files

You'll get more detail about --orphanarguments in the doc : http://git-scm.com/docs/git-checkout

您将在文档中获得有关--orphan参数的更多详细信息:http: //git-scm.com/docs/git-checkout

回答by Pranav Patil

Create the branch on your local machine and switch in this branch

在本地机器上创建分支并切换到这个分支

$ git checkout -b [name_of_your_new_branch]

Push the branch on github :

在 github 上推送分支:

$ git push origin [name_of_your_new_branch]

You can all branches with current working branch with * mark by using below command:

您可以使用以下命令使用带有 * 标记的当前工作分支的所有分支:

$ git branch

Also You can find complete list of all git branching and merging files Create a new branch with git and manage branches

您还可以找到所有 git 分支和合并文件的完整列表使用 git创建一个新分支并管理分支