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

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


当前回答

我在我的.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
}

其他回答

自2013年1月以来,GitHub包括删除分支按钮旁边的“Branches”页面中的每个分支。

相关博客文章:创建和删除分支

git push origin --delete <branch Name>

较容易记住

git push origin :branchName

许多其他答案都会导致错误/警告。git branch -D branch_to_delete如果未完全合并到some_other_branch例如。

git checkout some_other_branch
git push origin :branch_to_delete
git branch -d branch_to_delete

如果您删除了远程分支, 不需要远程剪切。 它只用来获取您正在跟踪的仓库中可用的最新的远程 。 我观察到了git fetch添加遥控器, 而不是删除它们。 这里举例说明何时git remote prune origin将实际做一些事情:

用户 A 执行上述步骤。 用户 B 将运行以下命令以查看最新的远程分支 :

git fetch
git remote prune origin
git branch -r

执行前执行前

git branch --delete <branch>

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

git ls-remote

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

简单说一句:

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