… it’s worth checking what version of git you have. (More on that below.) If you change directory into the submodule then you’ll find that it doesn’t know anything about the the parent project at all, and you can carry out operations in that repository as if it were standalone. It’s important to understand that the repository which contains a submodule knows very little about it except for which version it should be and various bits of information about how to update it. (I’ll sometimes refer to the whatdotheyknow repository as the super-project, which I hope is clear.) In each project the commonlib repository has been added as a submodule. The example I’m going to use in this post however, called whatdotheyknow, is one of the various mySociety projects that depend on a repository called commonlib, which contains useful code common to at least one project. For example, if you’re developing a new Ruby-on-Rails application, you could add a clearly specified version of the Rails repository as a submodule at the path vendor/rails. This is a useful feature when you have a project in git which depends on a particular versions of other projects. What are submodules?Ī submodule in a git repository is like a sub-directory which is really a separate git repository in its own right. Submodules in git are commonly misunderstood in various ways, and although the explanation in the official manual is clear and pretty easy to understand, I thought that a different treatment here might be useful to someone. In short, git submodules looks like a good idea, but they aren’t really workable in the real world.I haven’t actually finished the FAQ bit of this post yet, but since I’m not sure when I’ll have time to do so, I’ll just publish it anyway – please let me know in the comments if this is useful for you, or there’s something else you’d like to see included. It gives a new meaning to “it works on my machine”. Of course, if there is an update to the original submodule, you need to have two stages to update that.Īnd we haven’t spoken yet on the fun of pushing the main repository but forgetting to push the submodule. You need to push your changes to the submodules somewhere, and that means that if you need to fork the original project, update references to the project. Not if you intend to share this with other people. Let us assume that I want to make a change that is local to just this project. PS C:\Work\temp\R1\Legal > git commit -m "adding disclaimer"Īnd here is where the problems starts. Then it starts to become somewhat messy.įor example, let us say that I want to add a disclaimer in R1: PS C:\Work\temp\R1\Legal > echo "Not for Jihad use" > Disclaimer.txt ![]() Until you start sharing this with other people. Now, this looks nice, and it works beautifully. PS C:\Work\temp\R2 > git submodule add C:\Work\temp\Lic Legal PS C:\Work\temp\R1 > git submodule add C:\Work\temp\Lic Legal I can do that with submodules, like so: PS C:\Work\temp\R1 > git submodule init Now I want to share the license.txt file between the projects. PS C:\Work\temp\Lic > git commit -m "initial commit" PS C:\Work\temp\Lic > echo "Copyright Ayende (C) 2011" > license.txt ![]() PS C:\Work\temp\R2 > git commit -m "initial commit" PS C:\Work\temp\R2 > echo "Hello Jane" > Jane.txt initial commitġ files changed, 0 insertions(+), 0 deletions(-) PS C:\Work\temp\R1 > git commit -m "initial commit" PS C:\Work\temp\R1 > echo "Hello Dolly" > Dolly.txt Initialized empty Git repository in C:/Work/temp/Lic/.git/ Initialized empty Git repository in C:/Work/temp/R2/.git/ ![]() Initialized empty Git repository in C:/Work/temp/R1/.git/ Here is our basic setup: PS C:\Work\temp > git init R1 Obviously I want all projects to use the same license and the whole thing to be under source control. Let me present you with a simple scenario, okay? I have two projects that share a common license. You can’t fork easily with submodules, well, you can, if you really feel like updating the associations all the time.And that assumes that you have access to them. You can’t branch easily with submodules, well, you can, but you have to branch in the related projects as well.You can’t just download the entire source code from github.You can’t just git clone the repository, you need to clone the repository, then call git submodule init & git submodule update.The builtin answer for sharing code between multiple projects is quite simple…īut it introduces several problems along the way:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |