git 如何从命令行删除远程分支(例如 Github)?

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

How to delete remote branch (e.g. Github) from command line?

gitgithubversion-control

提问by Masked Man

I have a git repository in my local machine:
I add a new branch called testand add a few commits
Then I checkout to masterbranch and add commits to it.
So I use git push --all githuband continue working on master. After some time I decide to completely remove the testbranch and use: git branch -d testand git branch -r -d github/test, but it only deletes the local branch used for tracking the actual testbranch as git says:

我的本地机器上有一个 git 存储库:
我添加了一个名为的新分支test并添加了一些提交
然后我结帐到master分支并将提交添加到它。
所以我使用git push --all github并继续在 master 上工作。一段时间后,我决定完全删除test分支并使用: git branch -d testand git branch -r -d github/test,但它只删除用于跟踪实际test分支的本地分支,如 git 所说:

Deleted remote-tracking branch github/buggy (was acc5a58).
删除了远程跟踪分支 github/buggy(原为 acc5a58)。

I'm asking if there's a way to actually remove the testbranch from github servers from command-line?

我在问是否有办法test从命令行从 github 服务器中实际删除分支?

采纳答案by Arkadiusz Drabczyk

As with every gitserver:

与每台git服务器一样:

$ git push github :<BRANCH_NAME>

or:

或者:

$ git push github --delete <BRANCH_NAME>

Example:

例子:

$ git push github --delete test

回答by Mihir Patel

Local Branch

本地分行

git branch -d local_branch

Remote Branch

远程分支

git push origin --delete remote_branch

回答by blue112

Use this command:

使用这个命令:

git push github :test

Read "push nothing as refname teston github remote"

阅读“test在 github 远程推送任何内容作为 refname ”