Open findxc opened 1 year ago
--depth=100
git clone --depth=100 <repo>
git fetch origin another_branch
git checkout another_branch
git config --list
remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
+refs/heads/*:refs/remotes/origin/*
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --unshallow
相关文档:
--depth=100
,比如git clone --depth=100 <repo>
来只 clone 主分支并且只 clone 100 个 commit ,由于 clone 内容大大减少, clone 就变快了git fetch origin another_branch
然后git checkout another_branch
无法像以前一样基于远端的 another_branch 新建一个本地分支。执行git config --list
发现remote.origin.fetch
的值是+refs/heads/master:refs/remotes/origin/master
,而其它仓库的这个值一般是+refs/heads/*:refs/remotes/origin/*
,我们这里是这个值是因为 clone 有 depth 参数, git 自动设的,所以我们手动执行git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
改回去就行了,这一点的详细解释见 How do fetch remote branch after I cloned repo with git clone --depth 1 - Stack Overflowgit fetch --unshallow
拉取完整记录,执行完后就和没加 depth 的 clone 一样了相关文档: