Git and Submodules
This is an open discussion with 15 replies, filed under General.
Search
I still don’t get submodules. When I add a few lines of your example to .gitmodules
both git submodule init
and git submodule update
don’t do anything. However when I clone Symphony from Github, both of them work…
It is a weird thing. I have the O’Reilly Git book, and it advises never to use it as it continues to change with each version…
Just thought I’d try and be helpful… ;)
PS, I’ve just tried it myself, and yeah, it don’t work… After digging a little, turns out they have to be added with git submodule add
to add them to the index. Bummer.
I should never assume anything, but at least there is a quick list of some cool extensions!
Yup… I’ve just submodule-ified my first project. git rm -r
and git submodule add
all the way but it’s working fine now.
It took me hours to get that list together too…
- Find the extension
- Go to the Git site
- Choose the Git read-only url
- git submodule add
- do a few then git submodule update —init
- Do a commit
What a ball ache! I should learn bash and write a script to do it.
I’ve played around a little bit and it seems safe to:
- Clone the official repository
- Remove the
workspace/
line from.gitignore
(otherwise git will complain when you try adding it as a submodule) - Add your workspace as a submodule
- Add extensions using submodules
- Pull from the official repo for updates anytime you want
It is not okay to download the ZIP, add submodules, then add the official repo as origin and hope everything will work out. It simply won’t (you’ll end up with at least having to add all submodules again)… :-)
However I still don’t get how I can pull updates from the submodules. git submodule update
apparently doesn’t do that.
I did it the same sort of way you have. I think because the submodule command is still in development and discussion in the Git community, it changes and isn’t perfect yet.
However I still don’t get how I can pull updates from the submodules. git submodule update apparently doesn’t do that.
cd
into the submodule directory and git pull
?
Doing that gets the entire repo, submodule
only pulls the default branch, to lighten the load of your own repo.
It’s a very bizarre command, and will more than likely change very soon to something else! lol
What if you cd
into the extension folder, then git init
to initialise that directory’s git reference and then git pull
. Not sure if that’s even possible but it sounds like it should work, since each submodule is its own repo with a .git
hidden directory that can be initialised.
That’s right, and it is possible…
If you do
git submodule update --init
to pull and update all of your extensions, then like Nick said
git pull
in the extension folder you want to do detailed work on. You’ll end up in a detached head state though for the extension you’ve pulled however, so doing the first command again from the root minus the --init
will revert your extension to the commit stored in your index file, as it is controlled by the main repo submodule
command. It’s imperative then that you commit
straight after the extension pull/fetch/checkout
etc.
The other option is to just clone
all the extensions you want into the /extensions folder, but that gives you a very heavy repo if you have as many extensions as I do, the entire history of every extension would be pulled down.
Yeah, git pull
in each submodule actually makes perfect sense… :-)
Okay, to reiterate. After git pull
ing a submodule, you will see a +
in front of the hash for each updated submodule in git submodule status
. This tells you that you have a newer version of the submodule that hasn’t been commited yet (don’t forget to add
the directory in question first).
However, when I do git submodule update
again after pulling, it will create a new, unnamed branch in the submodule in question. The master
branch from the latest pull
will remain untouched.
Uh, god it’s complicated…
Just found this bash script recursively updating git submodules maybe it can be adapted to adde the submodules too?
has anyone figured out a good way around the issue that presents itself when switching branches that have different submodules?
for those that haven’t experienced it, if you add submodules to one branch and then checkout another branch that doesn’t have them, you will get this error:
warning: unable to rmdir extensions/dashboard: Directory not empty
this will leave all of your submodules in the file structure, but unstaged. a google search brought up this post from november:
This is because submodule deletion is not well supported at the moment. There has been a lot of discussion how to make git handle that better but no one implemented it so far.
perhaps somebody can direct me to a better method, but the context of the problem is in a repo where i have branches for both symphony-2/master
and symphony-2/integration
, with my own master
branch being where i work. this way, i can merge either the symphony stable or the symphony rc into my branch for testing.
edit: i just realized i can’t merge symphony-2/master
into my working branch if i’ve already merged integration
, it says it’s already up-to-date :(
hmm, this is an interesting command
git submodule update --init --recursive
Create an account or sign in to comment.
So then, I’ve just put together my first Git repository! I don’t know why I was so hesitant to move over from Subversion, it’s a breeze (well, I guess till something goes wrong).
It has taken me an age to get all my chosen extensions under the repo as submodules, and it made me think about posting a .gitmodule file, to make it easier for others… There’s 45 extensions here, it’s not all of them. Just drop this file in place of the cloned Symphony repo’s one and
git submodule update --init
and you’ll have more extensions.Hope it’s helpful?