清理旧的远程 git 分支 [英] Cleaning up old remote git branches

查看:21
本文介绍了清理旧的远程 git 分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两台不同的计算机(A 和 B)上工作,并在 dropbox 目录中存储了一个通用的 git 遥控器.

假设我有两个分支,master 和 devel.两者都在跟踪他们的远程对应方 origin/master 和 origin/devel.

现在,在计算机 A 上,我删除了本地和远程分支 devel.

git push origin :heads/develgit 分支 -d 开发

在计算机 A 上运行 git branch -a,我得到以下分支列表.

  • 大师
  • 起源/头部
  • 起源/主

在电脑B上运行git fetch,我可以用git branch -d devel删除本地的devel分支,但是不能删除远程的devel分支.

git push origin :heads/devel 返回以下错误信息.

<块引用>

错误:无法推送到不合格的目的地:heads/proxy3d
目标 refspec 既不与远程上的现有 ref 匹配,也不以 refs/开头,我们无法根据源 ref 猜测前缀.
致命:远端意外挂断

git branch -a 仍然列出远程分支中的 origin/devel.

如何清理电脑 B 的远程分支?

解决方案

首先,git branch -a在机器B上的结果是什么?

第二,你已经在origin上删除了heads/devel,所以你不能从机器B上删除它.

试试

git branch -r -d origin/devel

git remote prune origin

git fetch origin --prune

并随意将 --dry-run 添加到 git 语句的末尾,以查看运行它的结果,而无需实际运行它.

git remote prunegit branch.>

I work from two different computers (A and B) and store a common git remote in the dropbox directory.

Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel.

Now while on computer A, I delete branch devel, on local and remote.

git push origin :heads/devel
git branch -d devel

Running git branch -a on computer A, I get the following list of branches.

  • master
  • origin/HEAD
  • origin/master

Running git fetch on computer B, I can remove the local devel branch with git branch -d devel, but I can't remove the remote devel branch.

git push origin :heads/devel returns the following error messages.

error: unable to push to unqualified destination: heads/proxy3d
The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref.
fatal: The remote end hung up unexpectedly

git branch -a still lists origin/devel in the remote branches.

How can I clean up the remote branches from computer B?

解决方案

First, what is the result of git branch -a on machine B?

Second, you have already deleted heads/devel on origin, so that's why you can't delete it from machine B.

Try

git branch -r -d origin/devel

or

git remote prune origin

or

git fetch origin --prune

and feel free to add --dry-run to the end of your git statement to see the result of running it without actually running it.

Docs for git remote prune and git branch.

这篇关于清理旧的远程 git 分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆