Rename core .gitignore file to example.gitignore and add explanatory comments

Created on 27 May 2011, about 14 years ago
Updated 4 May 2025, about 1 month ago

Problem/Motivation

To include or not include an expanded .gitignore file as part of Drupal Core and/or include a gitignore.example file.

If you are using git for version control, it is recommended that you add settings.php (amongst others) to the .gitignore file so if you change it on your local system, you don't push that file(s) up to the server. However, if you are not using git (some people don't), there is an unneccessary file included with the distribution.

Also, if you are using git and a .gitignore file is included in core and you are "not supposed to hack core"; this would "prevent" developers from updating the .gitignore file for their environment.

Proposed resolution

This was resolved for Drupal 8 ONLY as Drupal 7 includes a .gitignore file in all production releases. Currently the best proposed solution is to never put .git in the drupal directory at all. It should reside 1 directory ABOVE drupal both for security reasons as well as a way to avoid core updates from affecting any .gitignore customization. This also allows Drupal to control it's own default .gitignore file rather than having to have something like example.gitignore which does no good. It's nice to have the settings and files directory pre-ignored using drupal core's default .gitignore file.

In Drupal 8.x, the .gitignore file was removed but an example.gitignore was added to use as a starting point.

Original report by [David Stosik]

Sorry, Saved instead of Previewing my post... Here is a rewrite.

Hello,

The easiest way to explain the problem is to describe my use case.

At Makina Corpus, our policy is too keep all projects contributed on Drupal.org out of the versioning system.
A website project usually consists of a Drush make file (containing references to all community projects, and possible patches, needed to build the project), custom modules, themes, and a profile.
To ease Git use, we also created a .gitignore file, placed at the root of the website project (Drupal root), describing all the ignored files, basically everything which is a contributed project, tracking with Git only the code we produce specifically for the project.
Here is an example :

# By default, ignore all files in root directory.
/*.*

# Exceptions
!/*.make
!/.gitignore

# Uncomment following line if modifying .htaccess ?
#!.htaccess

# Ignore Drupal folders
/includes
/misc
/modules
/scripts
/themes
/sites
/profiles/minimal
/profiles/standard
/profiles/testing

This .gitignore file is used on projects for which we produce a profile, as we put inside the profile all custom modules, features and themes. A project where custom modules are in sites/all/modules(/custom) would need slight adaptation.
The process to build the project is then to : first, clone the git repository locally, then run drush make on the project's make file, and finally run the installation, selecting the appropriate profile.
So that is what we had until now.

Enters Drupal 7.2
Today, I decided to update my project's code, so I ran the drush make file again (which downloads projects latest versions, except for those we specified a version number). Among them, it downloads Drupal 7.2, and its new .gitignore file, overwriting ours.
If I hadn't taken care during my next commit, I would have commited ALL project files (except the ones ignored by Drupal 7.2 .gitignore file) ! Which is what I called Git bombing on the issue title.

Moreover, it also means that now, as .gitignore is part of the Drupal core project, having one's own .gitignore file could be considered as a core hack (as it implies manual maintenance and ports over Drupal versions).

As a reminder, here is the .gitignore file added to Drupal 7.2 :

# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php

# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private

I see that only files inside sites/ folder are ignored, would it be possible to move Drupal 7 .gitignore file inside sites/ to allow developers to use their own at Drupal's root ?

Regards,

David

📌 Task
Status

Fixed

Version

8.0 ⚰️

Component

other

Created by

🇯🇵Japan David Stosik

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • git

    Used in Documentation issues for documentation related to Git

  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024