删除远程分支的尝试失败 :

$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.

$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.

$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).

$ git push
Everything up-to-date

$ git pull
From github.com:gituser/gitproject

* [new branch] bugfix -> origin/bugfix
Already up-to-date.

我如何正确删除本地和远程的远程/原产/bugfix分支?


当前回答

删除本地端 - (正常)

git branch -d my_branch

如果分行处于调整/合并的进度中,且未正确完成,这意味着您将会出错, 重设/ 计量在进行中, 因此在这种情况下, 您将无法删除分行 。

所以要么你需要解决重置/合并问题。 否则,你可以通过使用, 强制删除,

git branch -D my_branch

要删除远程 :

git push --delete origin my_branch

您可以使用 :

git push origin :my_branch   # Easy to remember both will do the same.

图形代表:

其他回答

其它许多答案都会导致错误/ 警告。 这个方法比较愚蠢, 虽然您仍然需要 git 分支 - D 分支 - D 分支_ to_ deletete , 如果它没有完全合并到其它分支中, 比如 。

git checkout some_other_branch
git push origin :branch_to_delete
git branch -d branch_to_delete

如果您删除了远程分支, 不需要远程剪切。 它只用来获取您正在跟踪的仓库中可用的最新远程 。 我观察过 Git 抓取将会添加远程, 而不是移除它们 。 下面的例子说明 Git 远程 Pinene 何时会真正做点什么 :

用户 A 执行上述步骤。 用户 B 将运行以下命令以查看最新的远程分支 :

git fetch
git remote prune origin
git branch -r

删除远程分支的命令行的替代选项是 GitHub 分支页面。

例如,见:https://github.com/agorm/agorgon.js/branches。

在代码 - > GitHub 库的分支页面中找到 。

我一般更喜欢指挥行本身,但这个 GitHub 页面显示您对分支的更多信息,例如最新日期和用户,以及前后承诺的数量。 这对于处理大量分支很有用。

很简单:

删除远程分支

git push -d origin <branch-name>

git push origin :<branch-name>

- 也可以用此语法删除标记

强制删除本地分支

git branch -D <branch-name>

注意: 在删除远程分支后, 在其它机器上进行 Git 抓取 -- all -- prune, 以删除过时的跟踪分支 。

示例示例示例示例

要删除本地分支

git branch -D my-local-branch

要删除远程分支

git push origin :my-remote-branch

随着新版本的Git, 也有可能删除分支

git push origin --delete <branch_name>

TIP: 如果您想要查看所有可用的分支, 您可以使用 git 分支 - a,

您可以使用 Git 分支 - r 查看远程分支

根据最新文件,使用终端,我们可以以以下方式删除。

删除本地语 :

git branch -D usermanagement

在远程位置删除 :

git push --delete origin usermanagement

您也可以使用 Git 远程光素来源来做此操作

$ git remote prune origin
Pruning origin
URL: git@example.com/yourrepo.git
 * [pruned] origin/some-branchs

它从 Git 分支 - r 列表中提取并删除远程跟踪分支 。