Kris
Kris

Reputation: 1423

Git submodules in github repo

In my project, im using a third party library. I had git cloned this lib in my project, and then had done git submodule init and git submodule update in the lib folder. I pushed my main project to github, but the contents of this third party lib were not sent and the lib folder appears like a green folder in my github project repo.

If i clone my main project on another machine, i dont have the contents of the lib there.So, should i git clone the lib again on the machine and run the init and update commands again or is there any way to push the contents of the 3rd party lib to my github repo ?

Thank You

Upvotes: 2

Views: 3197

Answers (4)

KANNAN B
KANNAN B

Reputation: 1

In my case, I tried to link a submodule from a git repo to my main git repo using git submodule add link/to/submodule submodulename and I pushed it into my main branch; it’s perfectly working in my current terminal.

But when I try to clone my main branch in another system's terminal, it does not include the files in the submodule.

I found that I need to update my submodule in new system's terminal, by using git submodule update --init --recursive or also you can do --init --recursive while you clone the main branch first time, so that the files in the submodule are cloned in the new terminal.

Upvotes: 0

wangd
wangd

Reputation: 21

I had the same problem: I wanted to try some code from a project repo hosted on github, and so I cloned it. None of the build commands worked until my coworker told me about the magic incantation:

git submodule update --init

which cloned the submodules referenced in the repo properly. None of this was clear to me either, from "git submodule help" or "man git-submodule".

Good luck!

Upvotes: 1

VonC
VonC

Reputation: 1323115

Note that since April, 30th 2013, when you view a repository with a submodule on github.com, you get useful links and information for the submodule:

submodule

You now can see what exact reference a submodule points to.

The Repository Contents API will reflect that SHA1.

curl https://api.github.com/repos/jquery/jquery/contents/test/qunit

{
  "name": "qunit",
  "path": "test/qunit",
  "type": "submodule",
  "submodule_git_url": "git://github.com/jquery/qunit.git",
  "sha": "6ca3721222109997540bd6d9ccd396902e0ad2f9",
  "size": 0,
  "url": "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
  "git_url": "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
  "html_url": "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9",
  "_links": {
    "self": "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
    "git": "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
    "html": "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9"
  }
}

Upvotes: 5

Arafangion
Arafangion

Reputation: 11908

Yes, the submodule is essentially a git repository of its own. The parent git project simply references a particular commit. Refer to the help for git submodule for the details as to how to maintain them. Yes, you do need to init and update the repository for each submodule, however, you will find that there are commands (in the help) that do a lot of that for you.

Upvotes: 1

Related Questions