At this point, we're ready to make our first commit

  • Make sure you're in the project root. (One level above the "web" directory)
  • git init Initialize an empty git repository

Now, I want to point out that we don't want to simply add everything to our repository, because we want to make sure that the settings.local.php file, for example, doesn't get committed.

There are a number of ways you can do this, I typically use a ".gitignore_global" file to prevent any project on my computer from ever adding a settings.local.php file. But that's not necessary for this series, so if you want more info about that, do a search for ".gitignore_global" and you'll find an article on GitHub with more info.

For the purposes of this session, we're just going to add a line to the .gitignore file in the project root.

  • Edit ".gitignore"
  • Add the following to that file
# Ignore the local settings file
web/sites/default/settings.local.php

Now, I can go ahead and stage everything in this project to be committed to Git.

Commit Locally

  • git add . Add everything in this directory (recursively)

If we check the files that are staged with git status, we can confirm that the settings.local.php file is not in the list.

So, we can commit everything to Git.

  • git commit -m "Initial commit" Creates the first commit to the Git repo with the message "Initial commit".

  • Finally, a git status will show that we have a "clean working directory", so we're good to go.

Push to remote repo

Create the repo on GitHub, BitBucket, or your Git host of choice. I'll push to one on GitHub.

git remote add origin git@github.com:ModulesUnraveled/drupal8site.git
git push -u origin master

What have we done so far?

Let's take a minute to recap what we have done to this point.

  • Downloaded Drupal 8 using Composer
  • Installed Drupal using Drupal Console
  • Setup our settings.php and settings.local.php files
  • Committed everything to git and pushed to a remote repo

Basically, one-time setup stuff. These are things you'll do at the beginning of every project, but only once per-project. In a later video we'll install this site on a production server - which is also a one-time thing - but otherwise, from here on out, we're going to be performing standard day-to-day site-building tasks that you'll do on a regular basis throughout the life of a project.