$ git clone <git-repo-url> --depth=1 repo
$ cd repo
现在浅克隆了一个git仓库repo。但仓库里查询远程分支只有一个默认分支(这里是 master
),没有其他分支(如 weekly
):
$ git branch -r
origin/HEAD -> origin/master
origin/master
查看git config:
$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
此时是无法拉取其他分支的。解决步骤如下:
$ git remote set-branches origin *
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
$ git fetch --depth=1 origin weekly
remote: Enumerating objects: 31, done.
...
* branch weekly -> FETCH_HEAD
* [new branch] weekly -> origin/weekly
$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/weekly
$ git checkout -b weekly origin/weekly
Switched to a new branch 'weekly'
branch 'weekly' set up to track 'origin/weekly'.
$ git branch -vv
master 908e654 [origin/master] xxxx
* weekly 2b54b23 [origin/weekly] xxxx
搞定~