Drupal 7 and Drupal 8 recently added a default (and sensible) .gitignore file to the standard repository, and while this solves some problems, it has also caused some confusion. (issue)
Here's a link to the actual new .gitignore. Essentially, it excludes the sites/default/files and sites/default/settings.php files from git source control.
What problems does having a default .gitignore solve?
- The biggest problem it solves is that patches submitted to drupal.org were accidentally including things that they never should have included (like people's settings.php files) We just don't need that information, thank you very much.
- It also sets a "best practice" for not source-controlling your files directory. Since the files directory is website-generated or user-generated content, it doesn't make any sense to put that in your git repository; most people have long come to a consensus on this, although not all agree.
What problems does having a default .gitignore create?
Mostly the problems created have to do with developer workflow.
- A dev site may contain lots of deliberately uncontrolled modules or themes or libraries.
- A site may want a completely different .gitignore due to various policy differences from the default.
How do I solve these problems?
Lots of ways:
- If you don't want sites/all to be controlled at all (you want to ignore all modules and themes and libraries), add a file at sites/all/.gitignore with the contents a single line containing nothing but
- Simply change the .gitignore and commit the change. You won't be pushing it up to 7.x right?
- If you track core code using downloads (and not git) you can simply change the .gitignore and check it into your own VCS.
- Add extra things into
.git/info/exclude. This basically works like .gitignore (it has good examples in it) and is not under source control at all.
- Add an additional master gitignore capability with
git config core.excludesfile .gitignore.customand then put additional exclusions in the .gitignore.custom file.
Note that only 1 and 2 are completely source-controlled. In other words, #3, 4, and 5 would have a slight bit of configuration on a deployment site to work correctly, but they work perfectly for a random dev site.
How do I exclude things from Git that should always be excluded (Eclipse .project files, Netbeans nbproject directories, .orig files, etc.)?
You can have a global kill file. I use ~/.gitignore for things that I don't ever want to see show up as untracked files. You can activate that with
git config --global core.excludesfile ~/.gitignore