2

I have cloned a remote repository on a particular branch as per this: How do I shallow clone a repo on a specific branch? However, now I need to checkout a different branch on this remote repo. How do I do that? This is a self hosted repository on GitLab (if that information is useful? New to Git!)

Edit: I cannot clone the entire repository (probably because it is too large) and I get a GnuTLS recv error (-9) every time I try cloning it. I have tried using the solutions suggested here git clone GnuTLS recv error (-9): A TLS packet with unexpected length was received however they do not seem to work.

dhanshreeA
  • 98
  • 9

3 Answers3

2

Using --depth implies --single-branch, to turn single-branch into multi-branch (default mode) try:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
git checkout *branch_name*
Alim Özdemir
  • 2,396
  • 1
  • 24
  • 35
0

It might not be the most elegant solution, and I don't know your needs or context, but I'd just clone it again from the same source you got it the first time, just without the shallow option.

You'll be able to work on the branch you wanted, and optionnally also push from that new repo. And if this was just a one-shot need, you could as well delete this temporary clone afterwards.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • I'd in fact want to do that however I get the GnuTLS recv error (-9) every time I try doing that probably because the repo is too big. – dhanshreeA Mar 25 '19 at 17:39
0

How far back do you have to go back in terms of number-of-commits so that you have the latest of both the branches? Let's say that the number is 20. Then you can try the following

git clone --depth 20 path-to-repo
Note: This will get all the branches
Sid A
  • 1
  • 1