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

$ 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.

我如何正确删除remotes/origin/bugfix本地和远程分支?


当前回答

您可以在此删除与 Glob 或任何分支名称相对应的远程分支 :

git branch -r --list "origin/*" | xargs git branch -r -D

其他回答

简单说一句:

git branch -d <branch-name>
git push origin :<branch-name>

内容提要

git push -d <remote_name> <branchname>
git branch -d <branchname>

注:在大多数情况下,<remote_name>origin.

删除本地分处

删除当地当地使用下列分支之一:

git branch -d <branch_name>
git branch -D <branch_name>
  • 缩略-d的别名选项--delete,只有在该分支已经完全并入其上游分支的情况下,该分支才删除。
  • 缩略-D的别名选项--delete --force,删除分支“不管其合并地位如何”。 [资料来源:man git-branch]
  • 截至截至Git v2.3 吉特 v2.3, git branch -d(删除)学会尊重-f(力)旗。
  • 如果您试图删除当前选中的分支, 您将会收到错误 。

删除远程分支

截至截至Git v1.7.0,您可以删除偏远分支使用分支

$ git push <remote_name> --delete <branch_name>

可能比人们记忆起来容易

$ git push <remote_name> :<branch_name>

添加在Git v1. 5.0"删除一个远程分支或标签"

开始于Git v2.8.0,您也可以使用git push和和-d用作别名选项--delete因此,您安装的 Git 版本将决定您是否需要使用更简单或更难的语法。

删除远程处[原件:2010年1月5日的答复]

第3章普罗吉特Scott Chacon写道:

正在删除远程分支

假设你已经用一个远程分支完成了,比如,你和你的合作者完成了一个功能,并将其合并到您的远程主要分支(或您稳定的代码线中的任何分支)。您可以用相当模糊的语法删除一个远程分支。git push [remotename] :[branch]。如果您想要从服务器中删除服务器上的服务器固定分支,您将运行以下操作:

$ git push origin :serverfix
To git@github.com:schacon/simplegit.git
 - [deleted]         serverfix

boom 。 在您的服务器上不再有分支。 您可能想要在这个页面上粘住树枝 , 因为您需要这个命令, 您可能会忘记语法 。 记住这个命令的一个方法就是提醒git push [remotename] [localbranch]:[remotebranch]之前我们讨论过的语法 如果你离开[localbranch]你基本上在说,“不要拿我这边的任何东西,让它成为[remotebranch].”

印本印发 印发git push origin: bugfix斯科特·查孔是对的狗狗耳朵该页(或几乎是狗耳朵,在Stack overflow上回答这个)。

那你就应该在其他机器上执行这个

# Fetch changes from all remotes and locally delete 
# remote deleted branches/tags etc
# --prune will do the job :-;
git fetch --all --prune

以传播变化。

本地删除 :

要删除本地分支,请使用:

git branch -d <branch_name>

强行删除分支,使用-D代替-d.

git branch -D <branch_name>

远程删除 :

有两个选项:

git push origin :branchname

git push origin --delete branchname

我建议你用第二种方式,因为它更直观。

使用 :

git push origin :bugfix  # Deletes remote branch
git branch -d bugfix     # Must delete local branch manually

如果您确定要删除,请运行

git branch -D bugfix

现在清理已删除的远程分支, 运行

git remote prune origin

两者酷AJ86号A. 兵器答案非常相似。 我回过头来试图理解支持子模块替换的更好方法。 下面是两者的组合。

首先将 Git Bash 导航到 Git 仓库的根部, 以便分割 。 在我这里的示例中, 就是~/Documents/OriginalRepo (master)

# Move the folder at prefix to a new branch
git subtree split --prefix=SubFolderName/FolderToBeNewRepo --branch=to-be-new-repo

# Create a new repository out of the newly made branch
mkdir ~/Documents/NewRepo
pushd ~/Documents/NewRepo
git init
git pull ~/Documents/OriginalRepo to-be-new-repo

# Upload the new repository to a place that should be referenced for submodules
git remote add origin git@github.com:myUsername/newRepo.git
git push -u origin master
popd

# Replace the folder with a submodule
git rm -rf ./SubFolderName/FolderToBeNewRepo
git submodule add git@github.com:myUsername/newRepo.git SubFolderName/FolderToBeNewRepo
git branch --delete --force to-be-new-repo

下面是上面的复制件, 上面有自定义的可替换名称, 代之以 HTTPS 。 根文件夹是现在的 。~/Documents/_Shawn/UnityProjects/SoProject (master)

# Move the folder at prefix to a new branch
git subtree split --prefix=Assets/SoArchitecture --branch=so-package

# Create a new repository out of the newly made branch
mkdir ~/Documents/_Shawn/UnityProjects/SoArchitecture
pushd ~/Documents/_Shawn/UnityProjects/SoArchitecture
git init
git pull ~/Documents/_Shawn/UnityProjects/SoProject so-package

# Upload the new repository to a place that should be referenced for submodules
git remote add origin https://github.com/Feddas/SoArchitecture.git
git push -u origin master
popd

# Replace the folder with a submodule
git rm -rf ./Assets/SoArchitecture
git submodule add https://github.com/Feddas/SoArchitecture.git
git branch --delete --force so-package