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

$ 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本地和远程分支?


当前回答

两者酷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

其他回答

这是所有其它答案的混结。 它需要Ruby 1.9. 3+, 并经过测试仅仅OS X上写着

调用此文件git-remove,然后使用,例如,git remove temp.

#!/usr/bin/env ruby
require 'io/console'

if __FILE__ == $0
      branch_name = ARGV[0] if (ARGV[0])
      print "Press Y to force delete local and remote branch #{branch_name}..."
    response = STDIN.getch
    if ['Y', 'y', 'yes'].include?(response)
      puts "\nContinuing."
      `git branch -D #{branch_name}`
      `git branch -D -r origin/#{branch_name}`
      `git push origin --delete #{branch_name}`
    else
      puts "\nQuitting."
    end
end

使用吉特巴什您可以执行以下操作:

git branch --delete <branch>

-

从 GitHub 桌面应用程序中删除当地当地通过分支通过分处菜单条 :

Enter image description here

如果你(如果)不属于使用 GitHub 桌面应用程序, 并正在使用像视觉工作室那样的 IDE 来控制本地源码, 您只需要快速的一步 :

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

然后,一旦登录到您的 GitHub 账户, 一旦登录到您的 GitHub 在线账户, 转到存储库并单击所有各处选项卡。从此选项卡中,单击您想要删除的分支名称右侧的小垃圾桶图标。

Enter image description here

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

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

git push --delete origin serverfix

git push origin :serverfix

但它可能更容易记住。

两者酷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

执行前执行前

git branch --delete <branch>

确保您首先确定精确远程分支的名称是执行 :

git ls-remote

这将告诉您要进入什么精确用于<branch>值 。 () (branch案件敏感! )