Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Wordpress with Git - which files should I ignore?

Tags:

git

wordpress

For the past 6 or so months I have been working on Laravel projects that are closer to web apps rather than full, content managed sites.

Recently I've started a Wordpress project and there's something that baffles me, how do you use Git with WordPress?

I ask because in Laravel you can basically push everything asides from node_modules, storage and the composer vendor folder.

I have also read that it is not a good idea to store wp-config in your repository, it's a strange one as Laravel uses an .env file to similar effect.

I found the following .gitignore

*.log
wp-config.php
wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/blogs.dir/
wp-content/cache/
wp-content/upgrade/
wp-content/uploads/
wp-content/mu-plugins/
wp-content/wp-cache-config.php
wp-content/plugins/hello.php
/.htaccess
/license.txt
/readme.html
/sitemap.xml
/sitemap.xml.gz
like image 699
Jesse Orange Avatar asked Feb 08 '19 15:02

Jesse Orange


People also ask

What files should be ignored in Git?

Ignored files are usually build artifacts and machine generated files that can be derived from your repository source or should otherwise not be committed. Some common examples are: dependency caches, such as the contents of /node_modules or /packages. compiled code, such as .o , .

Does Git work with WordPress?

As the name suggests, WordPress GitHub Sync enables you to sync your WordPress site with any Git host. It offers standard Git functionality, recording all changes to your site along with the users who made them. However, it also enables external users to submit proposed changes through GitHub.

Is GitHub good for WordPress?

GitHub — along with Git itself — helps you implement version control for your codebase, which can be really handy for WordPress development and project collaboration. Additionally, GitHub Pages provides a convenient free hosting space for a WordPress site, as long as you're ok with using a static WordPress approach.

Which files should be checked in Git with WordPress?

Originally when I started using Git with my WordPress projects, I checked in all the files (WordPress core, plugins, themes, and even uploads). Over time I’ve found that to be less than ideal. My preferred .gitignore file appears below and it ignores everything by default.

What gitignore do you use for WordPress projects?

Note: While I use this .gitignore for WordPress projects, for stand-alone plugins or themes I use a general .gitignore. # By default all files are ignored. You'll need to whitelist

What happens if--cached is not added to git repository?

The --cached piece is important; if you don’t add that you’ll not only remove the files from the git repository, but also from the file system. Hope this helps. ::

How important is the--cached piece in Git?

The --cached piece is important; if you don’t add that you’ll not only remove the files from the git repository, but also from the file system. Hope this helps.


1 Answers

You can ignore almost everything with the following exceptions:

  1. wp-content/themes/my-theme (your theme and/or child theme)
  2. wp-content/plugins/my-custom-plugin. (any custom plugins you create)

Additionally, I have found two very good sources for gitignore files for WordPress. The first which is very straightforward is on gitignore.org (https://gitignore.org/gitignore.html#wordpress) and the second which is extremely surgical is by Sal Ferrarello and can be found here: https://salferrarello.com/wordpress-gitignore/

Just modify as required and of course, avoid the config.php. It has install specific info such as your database host & login which you may not want to expose to prying eyes.

like image 53
simlpymarkb Avatar answered Sep 20 '22 09:09

simlpymarkb