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

$ 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 push origin :bugfix  # Deletes remote branch
git branch -d bugfix     # Must delete local branch manually

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

git branch -D bugfix

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

git remote prune origin

其他回答

您也可以使用以下内容删除远程分支

git push --delete origin serverfix

git push origin :serverfix

但它可能更容易记住。

另一种办法是:

git push --prune origin

警告: 这将删除所有本地不存在的远程分支。 或者更全面地说,

git push --mirror

将有效地使远程存储库看起来像本地版本的存储库(本地负责人、远程和标签在远程镜像) 。

AcolAJ86 和 apentwarr 的回答都非常相似。 我反复地在两个小组之间走来走去,试图了解支持子模块替换的更好方法。 下面是两者的组合。

首先将 Git Bash 导航到 Git 仓库的根部, 以便分割 。 我这里的例子就是 ~/ Documents/ irstRepo( 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

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

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

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

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

使用 Git Bash 您可以执行以下操作 :

git branch --delete <branch>

- 带

从 GitHub 桌面应用程序中, 当您检查了分支时, 您可以通过分支菜单条删除本地分支 :

如果您没有使用 GitHub 桌面应用程序, 并且正在使用像视觉工作室那样的 IDE 来控制本地源码, 您只需要采取几个快速步骤 :

检查您要删除的分支以外的分支。右键单击您想要删除的分支。从上下文菜单中选择删除选项。

然后,一旦在网上登录到您的 GitHub 账户, 转到仓库, 并单击所有分支的标签。 从那里, 单击小垃圾桶就可以在右侧您想要删除的分支的名称上图标 。

无需试图从你的网上存储库删除。