The .gitignore File

February 26, 2024

When you create a Drupal 10 project, several folders and files should be excluded from Git tracking for various reasons, like to prevent exposure of sensitive information and to reduce the repository size by avoiding unnecessary files. Here they are:

1. core Core directory includes all Drupal files that should never be modified. Updates should be installed through the management interface.

2. modules/contrib Drupal’s contributed modules download and go to the `modules/contrib` directory. As these can be gotten from Drupal.org, it is unnecessary to store them in the Git project tracking.

3. profiles/contrib Similar to `modules/contrib`, this directory is for downloaded contributed installation profiles.

4. themes/contrib This directory is for all contributed themes.

5. sites/*/files This directory includes files like images, compiled CSS or JavaScript files, etc., generated by your website.

6. vendor This contains third-party libraries that Drupal uses, and they can be downloaded via composer.

7. sites/*/settings.php Usually, each environment (local, dev, prod) has its own `settings.php`.

8. sites/*/settings.local.php Local settings file, you keep development settings like database credentials, so this file should not be tracked.

9. sites/*/services.yml and sites/*/services.local.yml They typically contain sensitive information.

Refer to the sample below for a .gitignore file content example:

# Ignore directories generated by Composer
/vendor/
/web/core/
/web/modules/contrib/
/web/profiles/contrib/
/web/themes/contrib/
/web/libraries

# Ignore sensitive information
/web/sites/*/settings.php
/web/sites/*/settings.local.php
/web/sites/*/services.yml
/web/sites/*/services.local.yml

# Ignore Drupal’s file directory
/web/sites/*/files/

# Ignore private files created by Drupal
/private/

Take note that Drupal core and modules/themes updates should be managed via Composer, and composer.lock file should be committed to git to ensure same versions across all environments.

This is a general guide, and the specifics may vary slightly based on your project’s setup and requirements.