Getting git submodules working

I have a Kirby site I’ve been working on for some time. It’s tracked in a git repo (which I also use to deploy to my web server). I’ve been unable to get git submodules working for updating the /kirby and /panel directories.

I understand that this is one way to initialize those directories as submodules:

git submodule add https://github.com/getkirby/kirby.git
git submodule add https://github.com/getkirby/panel.git
git submodule update --init --recursive 

Will that work to add them as submodule directories? Do I need to

rm -rf ./kibry ./panel 

before issuing those commands?

Thanks!

If you started with a copy of the starterkit repo, you can simply run git submodule update --init --recursive, as the submodules are already registered in that repository.
What exactly does not work and which error message is generated by Git?

1 Like

I did not start with the starterkit repo. I’ve been updating manually by downloading the Kirby zip file and copying the kirby and panel directories into my project repo.

If you want to use the git submodule add command, you need to delete those two folders first, otherwise it won’t work.

As an alternative, you can edit your git config file and add the .gitmodules file manually.

In that case the commands you posted are exactly the right way to setup everything. Simply make sure to delete the Kirby and Panel directories first and run the three commands. After committing, you now basically have your own starterkit repo with your own code. :wink:

But given there is the git submodule add command, it makes much more sense to simply use that. :stuck_out_tongue:

@lukasbestle Of course it makes more sense :stuck_out_tongue_winking_eye:

OK, I this worked, but now when I push the repo to the server to deploy it uploads an empty kirby directory. Any ideas?

Edit: Looks like this might be a bit complicated. E.g.,

I’m using the deployment method mentioned here:

Maybe add the command to update kirby from post-receive?

@gtc, are you pushing to github or to your own server? Some deployment options like dandelion and git-ftp don’t work with submodules. see: Deploying via Git

(See edited post above. Thanks!)

So, I found this. I’ve not untangled the instructions or tried it yet, but it seems to allude to the possibility of making this work.

http://aaronadams.ca/post/37345904654/git-push-with-submodules

[bump] Any ideas? Thanks!

according to this issue on the github page for dploy, version 2 should be released soon and supports submodules.

Interesting. Thanks. Guess I could just scp the files up if I’m not using git directly.

Hi,

as the new 2.1.2 is out I wonder if it is possible to add this as a submodule to an existing kirby project, i.e. there’s already a kriby folder but I want to sync it with the submodule now …

You can simply remove the existing folders, initialize a new Git repo (if not yet), and then add the submodules with

git submodule add git@github.com:getkirby/panel.git

And the same for the core, of course.

That was what I tried, but it failed with this message

'panel' already exists in the index

That should only happen if the submodule already exist. Do you have a .gitmodules file in your repo?

As far as I can tell no …

BTW: I’m using Tower to manage my repos.

You should be able to use the following:

cd kirby
git checkout master
git pull
git submodule update --init --recursive
cd ..

cd panel
git checkout master
git pull
cd ..

git add kirby panel
git commit -m "Update Kirby"