是否可以在 git 中创建一个新的、空的远程分支而无需推送?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2574266/
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-10 08:11:40  来源:igfitidea点击:

Is it possible in git to create a new, empty remote branch without pushing?

gitbranch

提问by vfclists

Most examples of creating remote branches involve pushing from a local branch

创建远程分支的大多数示例都涉及从本地分支推送

Is there a way of creating an empty remote branch without pushing?

有没有办法在不推送的情况下创建一个空的远程分支?

Is it also possible to create a local empty branch,check it out then link it to the new also empty remote branch without pushing?

是否也可以创建一个本地空分支,检查它然后将它链接到新的也是空的远程分支而不推送?

回答by VonC

As mentioned in the blog post "Start a New Branch on your Remote Git Repository":

正如博客文章“在远程 Git 存储库上启动新分支”中所述:

  • Creating a Remote Branch
  • 创建远程分支
git push origin origin:refs/heads/new_feature_name
  • Make sure everything is up-to-date
  • 确保一切都是最新的
git fetch origin
  • Then you can see that the branch is created.
  • 然后就可以看到分支创建完成了。
git branch -r

This should show ‘origin/new_feature_name'

  • Start tracking the new branch

这应该显示 ' origin/new_feature_name'

  • 开始跟踪新分支
git checkout --track -b new_feature_name origin/new_feature_name

So to declare a remote branch, even one which doesn't yet exist on the localrepository, git pushis mandatory.

因此,必须声明一个远程分支,即使是本地存储库中尚不存在的分支git push

回答by Onlyjob

git checkout --orphan new-empty-branch

Then

然后

git rm -rf .

to remove all files from new branch.

从新分支中删除所有文件。