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

↘锁芯ラ 提交于 2019-12-03 03:46:58

问题


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?


回答1:


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

  • 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
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 local repository, git push is mandatory.




回答2:


git checkout --orphan new-empty-branch

Then

git rm -rf .

to remove all files from new branch.



来源:https://stackoverflow.com/questions/2574266/is-it-possible-in-git-to-create-a-new-empty-remote-branch-without-pushing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!