git - 如何从 Git 中删除无效的远程分支引用?

标签 git branch remote-branch

在我当前的 repo 中,我有以下输出:

$ git branch -a
* master
  remotes/origin/master
  remotes/public/master

我想从分支列表中删除remotes/public/master:

$ git branch -d remotes/public/master
error: branch 'remotes/public/master' not found.

此外,git remote 的输出很奇怪,因为它没有列出 public:

$ git remote show 
origin

如何从分支列表中删除“remotes/public/master”?

更新,尝试了git push命令:

$ git push public :master
fatal: 'public' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

最佳答案

您可能需要清理:

git gc --prune=now

或者您可能需要修剪:

git remote prune public

prune

Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>".

With --dry-run option, report what branches will be pruned, but do no actually prune them.

但是,看起来这些应该早点用

清理掉
git remote rm public 

rm

Remove the remote named <name>. All remote tracking branches and configuration settings for the remote are removed.

所以可能是您手动编辑了您的配置文件而这并没有发生,或者您有权限问题。

也许再运行一次,看看会发生什么。


建议背景

如果您查看 revision logs ,你会注意到我建议了更多“正确”的技术,无论出于何种原因不想在他们的存储库上工作。

我怀疑 OP 做了一些让他们的树处于不一致状态的事情,导致它的行为有点奇怪,并且需要 git gc 来修复遗留的 cruft。

通常 git branch -rd origin/badbranch 足以破坏本地跟踪分支,或 git push origin :badbranch 破坏一个远程分支,通常从不需要调用git gc

关于git - 如何从 Git 中删除无效的远程分支引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1072171/

相关文章:

git - 显示不包含提交的分支

git - 如果我从一个分支中挑选一个提交然后 merge 整个分支,那么 git 历史会发生什么?

git - 如何查看两个分支之间的差异?

git 工作树与 "clone --reference"

git clone不带master分支

git - 无法推送到远程分支,无法解析到分支

git - 使用 Git 对所有远程分支进行头提交

git - git 是自动运行 "fetch"还是仅在我告诉它时运行?

versioning - 如何使用JIRA有效管理分支机构?

git - 如何将 Git 分支移出到它自己的存储库中?