I added a submodule:
git submodule add git://github.com/chneukirchen/rack.git rack
A file .gitmodules
was created like:
[submodule "rack"]
path = rack
url = git://github.com/chneukirchen/rack.git
And of course Git knows about it:
git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
I added a submodule by hand, for example, adding to that file:
[submodule "redcloth"]
path = plugins/redcloth
url = git://github.com/jgarber/redcloth.git
And I repeated the previous command:
git submodule init
Submodule 'rack' () registered for path 'rack'
git submodule update
(no output)
git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
So, as far I can see, what I added by hand is ignored. Is there some way to make Git aware of the lines added by hand in the .gitmodules file?
Note: I've also tried to add the lines by hand to the .git/config
file and that didn't work either.
Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.
Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .
You can treat a submodule exactly like an ordinary repository. To propagate your changes upstream just commit and push as you would normally within that directory.
Ok, so thanks to Adam I found the answer, was kind of obvious but nevertheless, here it is:
If you check what git submodule add
does, you'd notice that it does three things:
.gitmodules
file,.git/config
file.So, basically the only difference between a repo with a submodule added by hand and the one added via the git submodule
command is the contents of the repo itself.
Answering with the same example, you should:
$ git clone git://github.com/jgarber/redcloth.git plugins/redcloth
Add the following to the .git/config
file*:
[submodule "redcloth"]
url = git://github.com/jgarber/redcloth.git
Make sure at least you add them to the git repo:
$ git add plugins/redcloth
And then check if git actually is "aware":
$ git submodule status
0766810ab46f1ed12817c48746e867775609bde8 plugins/redcloth (v4.2.8)
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
*note that the "path" variable you use in the .gitmodules
file isn't needed in that file
You need to run
git submodule update --init --recursive
UPDATE:
the submodule add command actually clones the entire repo and adds the sha1 to the index.
This may be new behaviour as compared to previous versions of git, the clone was not done immediately.
If you don't have an entry in the index pointing the module to a particular commit, git submodule update refuses to do anything. This seems to be new behaviour.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With