Deleting a remote branch

心不动则不痛 提交于 2019-11-29 07:38:01

You need to remove it from the remote with the following command:

git push origin --delete hello

When you are running git branch -rd origin/hello you are deleting your local branch only. The code above removes it from the origin repo.

To delete a remote branch, use

git push origin :remotebranch

Everything else operates on the local repository only. In more recent versions of git, you can also

git push origin --delete remotebranch

As per the documentation, --delete means the same "as prefixing all refs with a colon".

If you are wondering about meaning of the :, it follows the standard syntax for push. Usually, you would write

git push origin localbranch:remotebranch

but here, you replace localbranch with "nothing", effectively deleting the remote branch.

VonC

Note that git branch only allows for deleting local references.

 git branch -r -D origin/hello

That only delete the local pointer to a remote tracking branch, but that has no influence on the remote repo content itself.
Only the git push origin :hello, as mentioned in the other answers, would do that.

Plus, that doesn't change the config branch.hello.fetch: it still references origin/hello, which is why the next fetch will re-create the remote tracking branch in your local repo.

git push origin --delete somebranch

is the way you delete a remote branch. If you are still on an old version of Git, you may need to use the old syntax:

git push origin :somebranch

which translates to "push nothing into somebranch on the remote pointed to by origin". The command is of the form "git push (which remote repo) (what local reference):(which remote reference). Omitting (what reference) is interpreted as "put nothing" into (which remote reference), effectively deleting it. The newer syntax is much more intuitive.

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