简体   繁体   English

如何获得本地PC上的所有远程分支?

[英]How can I get all the remote branches on local PC?

I have a very big repository. 我有一个很大的存储库。 To clone this I have used the following command one after another from up to down. 要克隆此文件,我从上到下依次使用了以下命令。

git clone --depth=1 <url>
git fetch --depth=100
git fetch --depth=1000
git fetch --unshallow
git fetch origin
git pull --all

But I can't get all the branches from remote. 但是我无法从远程获得所有分支。 I can see only following branches by git branch -a command 我只能通过git branch -a命令看到以下分支

* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

How can I get all the branch from remote? 如何从远程获取所有分支?

Following your comment on the error, a partial answer can be found at fatal: early EOF fatal: index-pack failed , by ingyhere . 在对错误进行评论之后,可以通过致命找到部分答案,即致命:早期EOF致命:索引包失败 ,作者是ingyhere Since you want all branches you needed an added flag. 由于需要所有分支,因此需要添加标志。 Run

git clone --depth=1 --no-single-branch <url>
git branch -a

Make sure you see all branches before you continue. 在继续之前,请确保查看所有分支。 The no-single-branch is the addition that counts. no-single-branch是重要的加法。

From the man: 从男人那里:

--depth depth -深度深度

Create a shallow clone with a history truncated to the specified number of commits. 创建一个浅表克隆,其历史记录被截断为指定的提交数。 Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. 表示--single-branch,除非给出 --no-single-branch来获取所有分支的尖端附近的历史记录。 If you want to clone submodules shallowly, also pass --shallow-submodules. 如果要浅层克隆子模块,则还要传递--shallow-submodules。

single-branch defaults to the main HEAD of the remote, master in your case. 默认情况下, single-branch默认为远程主机的主HEAD。

This will get all commits such that you have one commit in each branch. 这样将获得所有提交,这样每个分支中只有一个提交。 I'm not sure if they will be connected. 我不确定他们是否会连接。 Now you can pull them one by one, or 现在您可以一一拉动它们,或者

git fetch --unshallow
git pull --all

following the above answer. 按照上面的答案。 The above answer also states 上面的答案还指出

git config --global core.compression 0

before everything may help in case of failure. 万一发生故障,一切都会有所帮助。

You can try an alternative approach. 您可以尝试其他方法。 First create an empty repo git init . 首先创建一个空的repo git init

Then set remote url of the repo, which you wanted to clone 然后设置要克隆的仓库的远程URL
git remote add origin git@github.com:User/UserRepo.git . git remote add origin git@github.com:User/UserRepo.git Then fetch using git fetch . 然后使用git fetch

This way you might fail too, but git fetch will preserve what he already fetched. 这样您也可能失败,但是git fetch将保留他已经获取的内容。 So try fetching few times and you're done. 因此,尝试获取几次,您就完成了。

To keep invoking git fetch until succeed you can try: until git fetch; do echo "Trying Again.."; done 为了保持调用git fetch ,直到成功,你可以尝试: until git fetch; do echo "Trying Again.."; done until git fetch; do echo "Trying Again.."; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM