3

I have my WordPress project under Git and have WordPress as a submodule. I want to keep my theme development in a separate submodule, but within the current setup and am having some difficulties getting the theme setup as a submodule.

Here is my file system:

/.git (master repo)
/index.php
/wp-config.php
/wordpress (WordPress repo as a submodule)
/wp-content 
  themes
     test-theme (theme repo)
        .git
        index.php
        (etc...)

Now when I push my master repo to github, and try and clone it on another machine, the wordpress submodule downloads fine, but my theme folder does not, and I get an error about submodule not being defined.

I've tried using this to add my theme as a sub-module:

git submodule add ./wp-content/themes/test-theme/.git ./wp-content/themes/test-theme

but I get the following error: "remote (origin) does not have a url defined in .git/config"

How do I defined my theme repo as a submodule, when it is essentially hosted "inside" the project and not at a separate repository online?

Thanks.

lowe_22
  • 395
  • 1
  • 5
  • 14
  • I just put wp-content as root of my git and then use .gitignore to remove plugins that I don't want to see. Custom plugins and theme is tracked together. – Jure C. Aug 06 '12 at 13:24
  • Related: https://stackoverflow.com/questions/48052006/moving-the-git-repository-to-a-child-folder – Jesse Nickles Mar 02 '22 at 15:42

1 Answers1

5

I'm still relatively new to using submodules but I have been trying to do something similar and found two blog posts quite helpful: one by Clint Berry and another by David Winter.

The principle of a submodule is that it should have a separate repo and then when you add that submodule to a new project the add submodule command should be pointing to the repo:

git submodule add https://github.com/youruseraccount/test-theme.git ./wp-content/themes/test-theme
git init
git update

I believe this is why you are getting the error, there is no URL associated with the origin. Look in the files .gitmodule and .git/config to confirm. If I am correct, the git init will add the necessary entries in .git/config and git update this will pull the theme from the repo and put it into the subdirectory.

See here for how to commit changes to the submodule and here for how to remove the submodule.

Community
  • 1
  • 1
nsecord
  • 210
  • 3
  • 7