Integralist
Integralist

Reputation: 2211

Using Git Sub Modules to manage 3rd party dependencies?

I'm currently running a test to see how Git sub modules work in the hope that I can use them to manage 3rd party dependencies.

In my local test I have a folder with my main Git repo in it. I then have a sub folder called scripts which has a sub module created for the GitHub repo https://github.com/jrburke/requirejs/

When I initially set-up the sub module I obviously got ALL the files/folders within that 3rd party repo but the only file I was interested in was the require.js file (https://github.com/jrburke/requirejs/blob/master/require.js) I commited my changes including all redundant files/folders deleted and then waited for RequireJs to make a change to their code.

When the change happened I git pulled in and it seems that every file changed would get pulled down? Even though in my repo I had commited them as deleted it seems that the sub module would regardless pull down any files that had changed even though I clearly didn't want them.

So that is problem one. The second problem is I then delete the files again and go to commit but I can't commit because of merge issues? But I can't merge them because I've deleted them! I've seen this before and apparently the solution was to go into a specific .git folder and delete out the files so they couldn't be referenced but this just seems like a lot of work to manage 3rd party dependencies?

I just want to clone down a repo, delete any files I don't want and run a git pull whenever I hear about an update to the 3rd party code. Is there any way to achieve that, simply?

Upvotes: 2

Views: 878

Answers (1)

VonC
VonC

Reputation: 1329492

When the change happened I git pulled in and it seems that every file changed would get pulled down?

Sure it does: your parent repo still has a reference to the upstream jrburke/requirejs repo with a SHA1 referencing its full content.

If you really wanted to managed a modified version of that repo as a submodule, you would need to:

  • fork that repo
  • add your fork as a submodule
  • remove all files but one
  • git commit within that submodule, and push to your fork
  • add as a new remote named 'requirejs', pointing to jrburke/requirejs repo
  • get back to your parent repo and commit again (to record the new state of your submodule)

Then, within the submodule, you can 'git fetch requirejs', merge only the file that interest you to your own version, commit and push that to your fork.
As always, don't forget to go back to your parent repo, and commit again.

Upvotes: 3

Related Questions