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

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


当前回答

答案是好的, 但是, 如果您有一大堆分支, 逐个删除本地和远程的分支, 将会是一个无聊的任务 。 您可以使用此脚本将这些任务自动化 。

branch_not_delete=( "master" "develop" "our-branch-1" "our-branch-2")

for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do

    # Delete prefix remotes/origin/ from branch name
    branch_name="$(awk '{gsub("remotes/origin/", "");print}' <<< $branch)"

    if ! [[ " ${branch_not_delete[*]} " == *" $branch_name "* ]]; then
        # Delete branch remotly and locally
        git push origin :$branch_name
    fi
done
  • 列出您不想删除的分支
  • 绕过遥控器的分支 如果它们不在我们的“保护名单”里 就会删除它们

资料来源:立即删除 Git 分支

其他回答

删除分行

我们假设我们的分支“联系形式”的工作已经完成,我们已经将其纳入“主人”中。由于我们不再需要它,我们可以删除它(就地):

$ git branch -d contact-form

要删除远程分支 :

git push origin --delete contact-form

两者酷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 -d {local_branch}(使用-D而不是强制删除分支,而不检查合并状态);

  • 要删除远程分支来自服务器的 :git push origin -d {remote_branch}.

参考:Git: 删除分支( 本地或远程).

除了其他答案之外,我经常使用git_ remote_ 分支工具。这是一个额外的安装,但它能方便地与远程分支进行互动。在这种情况下,删除:

grb delete branch

我发现我也使用publishtrack命令非常常见 。

要删除本地本地- (正常)

git branch -d my_branch

如果分行进展迟缓,而且未适当完成,那表示你们是误入歧途的。Rebase/Merge in progress,在这种情况下,你将无法删除你的分支。

所以要么你要么你需要解决 重新定位/合并的问题。 否则,你可以用武力删除删除通过使用,

git branch -D my_branch

删除偏远:

git push --delete origin my_branch

您可以使用 :

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

图形代表:

Enter image description here