4

Using git 2.4.3 (Fedora 22), I can clone a repo using the --depth and -b options:

$ git clone --depth 1 -b release https://github.com/adobe-fonts/source-code-pro.git fonts/source-code-pro
Cloning into 'fonts/source-code-pro'...                                    
remote: Counting objects: 114, done.
remote: Compressing objects: 100% (113/113), done.
remote: Total 114 (delta 1), reused 105 (delta 1), pack-reused 0
Receiving objects: 100% (114/114), 7.27 MiB | 2.85 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Checking connectivity... done.

In theory git submodule add should support the same options. Unfortunately it doesn't seem to work:

$ mkdir foo
$ cd foo
$ git init
Initialized empty Git repository in /spare/local/arankine/foo/.git/
$ git submodule add --depth 1 -b release https://github.com/adobe-fonts/source-code-pro.git fonts/source-code-pro                        
Cloning into 'fonts/source-code-pro'...
remote: Counting objects: 35853, done.
remote: Compressing objects: 100% (5932/5932), done.
remote: Total 35853 (delta 35196), reused 30018 (delta 29921), pack-reused 0
Receiving objects: 100% (35853/35853), 12.95 MiB | 3.06 MiB/s, done.
Resolving deltas: 100% (35196/35196), done.
Checking connectivity... done.
fatal: Cannot update paths and switch to branch 'release' at the same time.
Did you intend to checkout 'origin/release' which can not be resolved as commit?
Unable to checkout submodule 'fonts/source-code-pro'

The intention here is to minimize the disk space required for these fonts, which are distributed as binary objects on the release branch of that repo. Only the latest binaries are relevant.

It's not obvious to me how to make this work, please advise.

Alastair
  • 4,475
  • 1
  • 26
  • 23

1 Answers1

0

Add your submodule first, without mention of a branch.

Then make your submodule track the right branch:

cd /path/to/your/parent/repo
git config -f .gitmodules submodule.<path>.branch <branch>

cd path/to/your/submodule
git checkout -b branch --track origin/branch
# if the master branch already exist:
git branch -u origin/master master

You might need to raise the depth in order to include commits part of the branch you want, instead of commits part of the default master branch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • How does this achieve the desired result? I think this does basically the same thing as omitting the `--depth` parameter from `submodule add`, or am I missing something? To be clear I've edited the question to describe the desired result. – Alastair Dec 29 '15 at 21:06
  • @AlastairRankine the idea was to use submodule add with --depth, *then* try and switching branch. – VonC Dec 29 '15 at 21:36