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

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


当前回答

根据最新文件,使用终端,我们可以以以下方式删除。

删除本地语 :

git branch -D usermanagement

在远程位置删除 :

git push --delete origin usermanagement

其他回答

内容提要

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

以传播变化。

最灵活的方式是使用自定义 Git 命令例如,在您的某处创建以下 Python 脚本$PATH名称下git-rmbranch并使它可执行 :

#!/usr/bin/env python3

import argparse
import subprocess
import sys

def rmbranch(branch_name, remote, force):
    try:
        print(subprocess.run(['git', 'branch', '-D' if force else '-d', branch_name],
                             capture_output=True, check=True, encoding='utf-8').stdout, end='')
    except subprocess.CalledProcessError as exc:
        print(exc.stderr.replace(f'git branch -D {branch_name}', f'git rmbranch -f {branch_name}'), end='')
        return exc.returncode

    return subprocess.run(['git', 'push', remote, '--delete', branch_name]).returncode    

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Delete a Git branch locally and remotely.')
    parser.add_argument('-r', '--remote', default='origin', help="The remote name (defaults to 'origin')")
    parser.add_argument('-f', '--force', action='store_true', help='Force deletion of not fully merged branches')
    parser.add_argument('branch_name', help='The branch name')
    args = parser.parse_args()

    sys.exit(rmbranch(args.branch_name, args.remote, args.force))

然后git rmbranch -h将会显示您使用信息 :

usage: git-rmbranch [-h] [-r REMOTE] [-f] branch_name

Delete a Git branch locally and remotely.

positional arguments:
  branch_name           The branch name

optional arguments:
  -h, --help            show this help message and exit
  -r REMOTE, --remote REMOTE
                        The remote name (defaults to 'origin')
  -f, --force           Force deletion of not fully merged branches

请注意git push origin --delete <branch_name>并删除本地远程跟踪分支(origin/<branch_name>))(因此不必在意这一点。

P. S. 您可以找到这个 Git 命令的最新版本在这里欢迎提出意见和建议。

现在,你可以做它与GitHub 桌面桌面应用程序。

启动申请程序后

  1. 点击含有分支的工程
  2. 切换到您想要删除的分支

    Switching branch

  3. 从“ Branch” 菜单中选择“ 不出版... ” , 将分支从 GitHub 服务器中删除 。

    Unpublish branch

  4. 从“ 空白” 菜单中选择“ 删除”分支组名称"""",""",""",""","""","""",""""","""","""""","""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    Delete local branch

之后我加了以下别名.gitconfig此选项允许我删除有分支或没有指定分支名称的分支。 如果没有通过参数, 分支名称默认为当前分支 。

[alias]
    branch-name = rev-parse --abbrev-ref HEAD     

    rm-remote-branch = !"f() { branch=${1-$(git branch-name)}; git push origin :$branch; }; f"
    rm-local-branch = !"f() { branch=${1-$(git branch-name)}; git checkout master; git branch -d $branch; }; f"
    rm-branch-fully = !"f() { branch=${1-$(git branch-name)}; git rm-local-branch $branch; git rm-remote-branch $branch; }; f"

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

git branch --delete <branch>

-

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

Enter image description here

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

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

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

Enter image description here

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