问题
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