0

The repo I'm working on is huge, approximately 55GB. It has more number of branches & It takes lots of storage space. So I decided to clone a single branch.

I cloned the master branch using the following command.

git clone -b master --single-branch <remote-repo-url>

I verified that only the master branch was cloned by navigating it to the project folder.

Next, I want to check out the development branch from the remote. I tried the following command,

git checkout --track origin/development

and it gives an error fatal: 'origin/development' is not a commit and a branch 'development' cannot be created from it

How can I check out a remote branch from a single branch?

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
DroidLearner
  • 2,115
  • 5
  • 31
  • 50
  • Does this answer your question? [GIT: Clone only specific branches from GitHub](https://stackoverflow.com/questions/58446026/git-clone-only-specific-branches-from-github) – Chris Maes Jun 16 '21 at 08:16

1 Answers1

3

You need to fetch the development branch first:

git fetch origin development:development

Consider using

git remote add -t development origin_development <remote_url>

to add a remote for the specific branches. Otherwise the --single-branch parameter causes your Git to not bother fetching and updating the remaining remote-tracking names that you'd probably like to have.

Inspired by this answer

Chris Maes
  • 35,025
  • 12
  • 111
  • 136