Drupal Core Installation As A Submodule


Well, where should we start? First off, get connected to the remote server to have a remote access to it (you can make use of ssh, for instance). You need to have two repositories initiated on the server - one for the core and the other for the site itself. It's on this site that the Drupal core will be installed on. We will create a user named "git" just for the purposes of illustrating. The repositories' initialization will then look like this:

cd /home/git/
mkdir bare
cd bare
mkdir core
mkdir project
cd core
git init --bare
cd /home/git/bare/project
git init --bare

Secondly, we will build a master branch in the core repository. It can be done at any testing ground once you have created a directory where core files will reside (in our instance it's /var/www/site_core), as well as have insourced the core git repository that had been created before (the remote server can be accessed through the following path ssh://git@ Next we perform the first commit to create the master branch in the repository. The relevant picture will read as follows:

cd /var/www/
mkdir site_core
cd site_core
git clone ssh://git@ ./
touch Readme.txt
echo 'Core repo' > Readme.txt
git add .
git commit -m "Initial commit"
git push origin master

Thus, we have Drupal core git repository fully initialized and on-the-go, though it still lacks the core files themselves. They should accordingly be added (mind that we are still in /var/www/site_core). The folders which can be affected in the course of elaborating the site should also be removed and placed over into .gitignore. Failing to do this will lead to putting the content of the above foulders to the initial state as soon as you have started the git submodule update command running. And that will effect removing the added modules. The foulders in question are "modules" and "sites":

git checkout -b 8.x
tar -xzvf drupal-8.x-dev.tar.gz -C /tmp && mv /tmp/drupal-8.x-dev/* /var/www/site_core
rm -rf sites/ modules/
git add .
git commit -m "Add core files"
git push origin 8.x
touch .gitignore
echo modules > .gitignore
echo sites >> .gitignore
git add .gitignore
git commit -m "Disalow modules and sites folders"
git push

If the chances are the rest of files can be affected, too, or some of the files can be added to the root while the site is being developed (say, .htaccess file or various html metrics files), such files should also be placed into .gitignore.

At this point we have the core repository up and running and available for use as a submodule. So now we are settling down to the site installation proper. For this, we will create (for testing purposes only) a catalog on the sever or locally  (e.g. new_site), where all site files will reside. The catalog's content should be retreived from the git repository of the site which had been created in the first stage, as well as the first commit should be performed to initialize the repository master branch:

cd /var/www/
mkdir new_site
cd new_site
git clone ssh://git@ ./
touch Readme.txt
echo 'Core project' > Readme.txt
git add .
git commit -m "Initial commit"
git push origin master

Now we are going to tackle the key point within the task, i.e. installing Drupal as a submodule. The following actions should be performed within the site's home directory.

Important: as long as the core will be displayed a a submodule now, it can't stay right in the home directory of the site any more, thus it should be properly placed into a certain directory (e.g. htdocs). The above effort is being taken to free the submodue directory from any files that are foregn to the matter. The installation process is as follows:

git checkout -b dev
git submodule add ssh://git@ htdocs
cd htdocs
git checkout 8.x

At the end of the day we have the site home directory  /var/www/new_site  with the Drupal core placed into /var/www/new_site/htdocs, which has been switched over to the required branch (8.x).

Now it's time to come back to the removed "modules" and "sites" foulders. We need them, though they can't be stored at the core submodule. Hence, they need to be created at the site root with the relevant links customized in a way that fakes the foulders' presence in the same directory with the core:

cd /var/www/new_site
mkdir sites
mkdir modules
ln -s /var/www/new_site/sites/ /var/www/new_site/htdocs/
ln -s /var/www/new_site/modules/ /var/www/new_site/htdocs/
git add .
git commit -m "Install Drupal core"
git push origin dev

Well, that's about it - the Drupal core as a submodule installation process is complete! Additional modules should be installed into the "modules" foulder, which is in the site root. With a view to illustrate the case, let's install the Administration menu module:

cd /var/www/new_site/
git submodule add --branch 8.x-3.x modules/admin_menu
git add .
git commit -m "Install admin menu module"
git push

So this is a concise review of how Drupal installation as a git submodule can be performed. We hope the above method will stand you in good stead.

5 votes, Rating: 5

Read also


At times, content importing appears to be the task which is far from trivial. Writing the import assignment out "from scratch" when aimed at covering each and every instance can't be practical,...


The article describes the CMS Drupal deployment process as performed with use of Oracle DB on Debian server.


Experienced Drupal developers can hardly do without Drush (Drupal shell) utility as it speeds up a good deal of...


Any web developer may face a situation, at times, when both -...


There are certain instances when you are being encouraged to implement access control practices that fulfill none of the criteria. That happens if,...

Need a quote? Let's discuss the project

Are you looking for someone to help you with your Drupal Web Development needs? Let’s get in touch and discuss the requirements of your project. We would love to hear from you.

Join the people who have already subscribed!

Want to be aware of important and interesting things happening? We will inform you about new blog posts on Drupal development, design, QA testing and more, as well news about Drupal events.

No charge. Unsubscribe anytime