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

$ 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

其他回答

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

启动申请程序后

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

    Switching branch

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

    Unpublish branch

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

    Delete local branch

内容提要

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 branch -D <name-of-branch>
git branch -D -r origin/<name-of-branch>
git push origin :<name-of-branch>

许多其他答案都会导致错误/警告。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

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