3

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

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

How can I get all the branch from remote?

MMHossain
  • 326
  • 2
  • 10
  • 1
    What happens if you just `git clone `? `git fetch` will only work on existing branches tracking the remote, which after a clone of `depth=1` is only `master`. – kabanus Apr 10 '18 at 07:23
  • git clone doesn't work because of large repository. It failed to clone several times. – MMHossain Apr 10 '18 at 07:50
  • This is the output of git clone Cloning into 'media'... warning: redirecting to remote: Counting objects: 40493, done. remote: Compressing objects: 100% (14693/14693), done. error: RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed – MMHossain Apr 10 '18 at 08:03
  • Please post that properly - it's very relevant. – kabanus Apr 10 '18 at 08:04
  • Also, if you're using a public remote such as `github` please note that as well. – kabanus Apr 10 '18 at 08:05
  • 2
    Have a look here https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches – dudster Apr 10 '18 at 08:46
  • Possible duplicate of [How to fetch all git branches?](https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches) – phd Apr 10 '18 at 09:58

2 Answers2

3

Following your comment on the error, a partial answer can be found at fatal: early EOF fatal: index-pack failed, by 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.

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. If you want to clone submodules shallowly, also pass --shallow-submodules.

single-branch defaults to the main HEAD of the remote, master in your case.

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.

kabanus
  • 21,167
  • 5
  • 30
  • 63
1

You can try an alternative approach. First create an empty repo git init.

Then set remote url of the repo, which you wanted to clone
git remote add origin git@github.com:User/UserRepo.git. Then fetch using git fetch.

This way you might fail too, but git fetch will preserve what he already fetched. 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

Al Mamun
  • 692
  • 6
  • 23