Critical situation in removing a local branch

喜夏-厌秋 提交于 2019-12-08 19:28:48

问题


I using the following command to remove a local branch with force delete option:

$ git branch -D <branch_name>

My question is, If I delete a local branch that had an upstream set and then do a normal push, it won't delete the remote branch right?

What should I do in this situation?


[NOTE]:

  • "-D" is force delete option.
  • I want delete the local branch and keep the remote branch in origin.


回答1:


git will only delete your local branch, please keep in mind that local and remote branches actually have nothing to do with each other. They are completely separate objects in Git.

Even if you've established a tracking connection (which you should for most scenarios), this still does not mean that deleting one would delete the other, too!

If you want any branch item to be deleted, you need to delete it explicitly.

Deleting local branches in Git

git branch -d <branch_name>

using a capital -D is like a "force" version of -d. If the branch isn't fully merged you'll get an error if you use the lowercase version. This again has no relevance to the remote branches and will only delete your local branch.

Deleting remote branches in Git

git push origin --delete <branch_name>

so to your question

If I delete a local branch that had an upstream set and then do a normal push, it won't delete the remote branch right?

You are correct it will not delete the remote branch.



来源:https://stackoverflow.com/questions/51295388/critical-situation-in-removing-a-local-branch

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