ruan-cat/monorepo

get-git-branch

- 诊断并修复 Git 仓库无法看到所有远程分支的问题,将受限的 fetch refspec 恢复为通配符模式, 使 git fetch 能拉取全部远程分支。当用户提及「看不到远程分支」「分支不全」 「只有 master/main」「fetch 所有分支」「shallow clone 补全分支」 「--single-branch 修复」「远程分支丢失」「获取全部分支」等关键词时使用此技能。 即使用户没有明确提到 refspec 或 shallow clone,只要意图是让仓库能看到并拉取所有远程分支, 就应触…

View source
Original skill document

Rendered from the source repository. Headings, examples, code, tables, links, and referenced images are preserved.

Get Git Branch

诊断并修复 Git 仓库的远程分支不可见问题,将受限的 fetch 配置恢复为完整模式。

背景知识

使用 git clone --depth=1git clone --single-branch 克隆仓库时,Git 会自动将 .git/config 中的 fetch refspec 限制为只拉取默认分支。例如:

ini
[remote "origin"]
    url = https://example.com/repo.git
    fetch = +refs/heads/master:refs/remotes/origin/master

这导致 git fetch --allgit branch -a 都只能看到默认分支,其他远程分支完全不可见。但远程仓库上那些分支仍然存在,只是本地配置不去拉取它们。

理解这个根因很重要——问题不在网络或权限,而在于本地的一行配置。

工作流程

第一步:诊断问题

同时执行以下三个命令,收集足够的信息来判断问题根因:

bash
# 1. 查看本地能看到的所有分支
git branch -a

# 2. 查看 fetch refspec 配置(关键诊断点)
git config --get remote.origin.fetch

# 3. 直接查询远程服务器上实际存在的分支
git ls-remote --heads origin

判断逻辑:

git config --get remote.origin.fetch 输出含义处理方式
+refs/heads/master:refs/remotes/origin/masterfetch 被限制为单分支继续第二步修复
+refs/heads/main:refs/remotes/origin/main同上(只是默认分支名不同)继续第二步修复
+refs/heads/*:refs/remotes/origin/*fetch 配置正常问题在别处,见「其他情况」

同时对比 git branch -agit ls-remote --heads origin 的结果:

  • 如果 ls-remote 显示的分支比 branch -a 多,确认是本地 fetch 配置问题
  • 如果 ls-remote 也只有一个分支,那远程确实只有一个分支,无需修复

第二步:修改 fetch refspec

将 fetch 规则从单分支改为通配符模式:

bash
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

这条命令将 .git/config 中的 fetch 行从:

plain
+refs/heads/master:refs/remotes/origin/master

改为:

plain
+refs/heads/*:refs/remotes/origin/*

星号 * 表示匹配所有分支名,这是正常 git clone(不带 --single-branch)的默认配置。

第三步:拉取所有远程分支

bash
git fetch --all

此时 Git 会按照新的通配符规则,从远程拉取所有分支的引用。

第四步:验证结果

bash
git branch -a

确认所有远程分支都已出现在 remotes/origin/ 下。向用户展示完整的分支列表。

第五步(可选):补全提交历史

如果仓库是浅克隆的(--depth=1),上述步骤只补全了分支引用,提交历史仍然是截断的。如果用户需要完整历史:

bash
git fetch --unshallow

这会下载完整的提交历史,耗时取决于仓库大小。只在用户明确需要时执行,因为大仓库的完整历史可能非常大。

判断是否为浅克隆:

bash
git rev-parse --is-shallow-repository
# true = 浅克隆,false = 完整历史

其他情况

如果 fetch refspec 已经是通配符但仍然看不到分支,按以下顺序排查:

  1. 网络问题git ls-remote --heads origin 是否能成功连接远程
  2. 权限问题:是否有权限访问远程仓库的所有分支
  3. 缓存过期:尝试 git remote update origin --prune 清理过期的远程引用
  4. 多 remote:检查 git remote -v,分支可能在其他 remote 上

注意事项

  • 修改 fetch refspec 是安全操作,不会影响已有的本地分支或工作树
  • git fetch --all 只下载引用和相关对象,不会自动创建本地分支或修改工作树
  • 如果用户需要在某个远程分支上工作,可以用 git checkout <branch-name> 自动创建追踪分支
from this repository

More skills

All skills
ruan-cat
Community

add-favicon

- 为文档站、前端站点或 monorepo 内多个站点补全或重做 favicon.svg。用户提到 favicon、浏览器标签页图标、Iconify、Lucide 风格、VitePress/VuePress 文档站、 public/favicon.svg、head link icon、图标太丑/一团浆糊/不要背景块时必须使用; 尤其适合批量为多个 VitePress 站点设计本地 SVG favicon,并显式配置 head。

installs
1
GitHub stars
5
Updated
Sep 4
ruan-cat
Community

git-commit

- 创建高质量的 git 提交:审查/暂存预期的变更,拆分为逻辑提交,并编写清晰的提交信息 (遵循 Conventional Commits 规范,支持 Emoji)。当用户要求提交代码、编写提交信息、 暂存变更或将工作拆分为多个提交时使用此技能。当用户提及【破坏性变更】关键词时, 必须按照本技能的 BREAKING CHANGE 规范使用感叹号格式编写提交信息。 优先针对 git 暂存区(staged)中的文件进行提交,只有当暂存区为空时才考虑整个工作树。 当用户提及【分门别类】关键词时,必须按照本技能的多提交拆分规范, 从文件类型、业务模块、修改类型、修改范围四个维度认真拆分多个提交。

installs
1
GitHub stars
5
Updated
Sep 4
ruan-cat
Community

init-playwright

- 在 pnpm monorepo 初始化 Playwright 三件套(@playwright/test + @playwright/cli + playwright-mcp),含 e2e/视觉测试骨架、MCP 配置、AI skills 生成、AI 记忆更新。 内置无头浏览器 CPU 过载事故复盘与故障排查指南:可排查 headless 模式下的 高 CPU 占用(100%)、浏览器卡死、Chromium 进程残留无法退出、 大屏 3D WebGL 渲染性能问题;提供紧急止损步骤和长期回归检查清单。 当用户提及 playwright 初始化、大屏视觉测试、e2e 测试搭建、 playwright monorepo 配置、pwcore/pwvisual MCP 等时触发。 也适用于无头浏览器性能故障排查、headless CPU 100% 诊断、 Chromium 进程残留清理、浏览器进程无法退出处理、 大屏 3D 渲染性能调优等排查场景。

installs
1
GitHub stars
5
Updated
Sep 4
ruan-cat
Community

init-simple-memorix

- Use when 用户提到 init-simple-memorix、Memorix hooks 过多或噪音、项目级或全局 hooks 配置、Memorix MCP 工具缺失、full 模式、WorkBuddy MCP 启动失败、信任审批、Node 参数兼容、setup 或升级后重新精简等场景。

installs
1
GitHub stars
5
Updated
Sep 4