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

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


当前回答

我用下面的 在我的巴什设置 :

alias git-shoot="git push origin --delete"

然后您可以拨打:

git-shoot branchname

其他回答

删除远程分支

git push origin :<branchname>

删除本地分支

git branch -D <branchname>

删除本地分支步骤 :

  1. 退出到另一个分支
  2. 删除本地分支

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

我在我的.bash_alians 文件中创建了以下方便功能 :

git-delete-branch() 
{ 
    if [[ -n $1 ]]; then
        git checkout master > /dev/null;
        branch_name="$1";
        echo "Deleting local $branch_name branch...";
        git branch -D "$branch_name";
        echo "Deleting remote $branch_name branch...";
        git push origin --delete "$branch_name";
        git remote prune origin;
        echo "Your current branches are:";
        git branch -a;
    else
        echo "Usage: git-delete-branch <branch_name>";
    fi
}

如果您有一个标签, 标签名称与遥控器上的分支相同, 这行不通 :

$ git push origin :branch-or-tag-name
error: dst refspec branch-or-tag-name matches more than one.
error: failed to push some refs to 'git@github.com:SomeName/some-repo.git'

在此情况下, 您需要指定要删除分支, 而不是标记 :

git push origin :refs/heads/branch-or-tag-name

类似地, 要删除标签, 而不是您要使用的分支 :

git push origin :refs/tags/branch-or-tag-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

以传播变化。