Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodule without extra weight

I'm not a Git master yet, faced a problem I can't figure out how to fix. I have a repo with my WordPress custom skeleton and I've added WordPress as a submodule from its original repo by git submodule add wp_repo_url. When I clone my repo to local machine with:

git clone --recursive https://github.com/user/repo local_dir

it downloads the WP submodule as expected, but here's the problem - actual files are only 20.7Mb, and in .git/modules/core/objects/pack I've got a huge 124Mb .pack file, which, I suppose, is smth like commit history / revisions of that submodule.

How can I re-add submodule or modify while cloning to prevent downloading this extra weight?

UPDATE:

With the help of @iclmam I've came up with the following setup:

  • my skeleton repo will have WordPress as a submodule, the whole original repo with history
  • when creating a new project from skeleton, I'll clone it without --recursive option to get only the main files and empty folder for submodule
  • IF I need WordPress with full history - for example, if I need to switch between different WP branches/tags to test my plugin/theme backward compatibility - then I'll get this submodule with full history
  • if I just need a plain clean install of recent WP version, I'll change into wp directory and go the old way:

    curl -L -O http://wordpress.org/latest.zip
    unzip latest.zip 
    mv wordpress/* .
    rm latest.zip  
    rm -rf wordpress
    

Not a perfect solution (I wanted to automate everything as much as possible), but it works for now.

Any advices on the original question are appreciated.

like image 655
Ihor Vorotnov Avatar asked May 08 '15 17:05

Ihor Vorotnov


1 Answers

since Git 2.10+ (Q3 2016), you will be able to do a regular clone... and still benefit from shallow clone for submodules.

All you need to do is record that configuration in your .gitmodules:

git config -f .gitmodules submodule.<name>.shallow true

Add, commit, and push: anyone cloning your repo (regular clone, full history) will get only a depth of 1 for the submodule <name>.

See commit f6fb30a, commit abed000 and commit 37f52e9 (03 Aug 2016) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit dc7e09a, 08 Aug 2016)

> submodule update: learn --[no-]recommend-shallow option

Sometimes the history of a submodule is not considered important by the projects upstream. To make it easier for downstream users, allow a boolean field 'submodule.<name>.shallow' in .gitmodules, which can be used to recommend whether upstream considers the history important.

This field is honored in the initial clone by default, it can be ignored by giving the --no-recommend-shallow option.

like image 89
VonC Avatar answered Nov 20 '22 20:11

VonC