get-git-branch
Installation
SKILL.md
Get Git Branch
诊断并修复 Git 仓库的远程分支不可见问题,将受限的 fetch 配置恢复为完整模式。
背景知识
使用 git clone --depth=1 或 git clone --single-branch 克隆仓库时,Git 会自动将 .git/config 中的 fetch refspec 限制为只拉取默认分支。例如:
[remote "origin"]
url = https://example.com/repo.git
fetch = +refs/heads/master:refs/remotes/origin/master
这导致 git fetch --all 和 git branch -a 都只能看到默认分支,其他远程分支完全不可见。但远程仓库上那些分支仍然存在,只是本地配置不去拉取它们。
理解这个根因很重要——问题不在网络或权限,而在于本地的一行配置。