7

I am configuring Git along with my WP development environment, and I was wondering what should be tracked and what should be ignored. If it makes sense to track plugins and for WP core. Create one repo for both theme & plugins?

Common sense would suggest that tracking WP as a whole, is overkill and unuseful, as I am not involved in core development and updates; of course, I want to track my theme/child-theme folder where my work is. Plugins?

So I wonder what is the suggested setup, how many repositories and what to track/ignore

References:

How should I structure a WP website project using git and updating from WP dashboard?

What is the best way to setup wordpress development environment for freelancers with version control?

  • 2
    if you don't track it as a whole, how exactly to you revert it to the state it was on 12/12/15? This is a question that will get different answers in different points in time and IMO is better to ask in SO how people maintain in git 3rd party libraries, as this is totally not a wordpress specific issue – Mark Kaplun Sep 8 '16 at 11:18
  • Well the question could be relevant to WP generally speaking on what parts are essential to include and what are not. For instance, if my project must be compatible with all WP versions maybe I could ignore the core from tracking? BTW, do you personally include the whole WP folder? – Riccardo Sep 8 '16 at 13:08
  • 1
    The question was old when I first encountered it in the late 90s while working on real time software for telecommunication equipment. In theory you just track everything that is related to the product excluding maybe auto generated. Tracking everything obviously include configuration in the DB ;). If your product is, or you prefer to treat it like a collection of sub modules, then tracking each module (theme, plugin) by itself is fine. Which is why this is a workflow question which can be answered differently for different types of projects and different wordflows – Mark Kaplun Sep 8 '16 at 13:23
  • The question in the end is why do you bother to track changes at all. If it is only because high rep people on WPSE say so, then you are likely to not do it fully right (just committing to git is not enough, branching, comment etc is also important). You should do it in order to find out when a breaking change was introduced and/or why the code was written that way. If you believe that core updates will never break your site, then no point in tracking core files, and same about plugins. – Mark Kaplun Sep 8 '16 at 13:31
  • Personally I just committed few hours ago just plugins and themes directories which just means that I am as lazy as everyone else, and I don't believe that for that specific project at this stage tracking core is important – Mark Kaplun Sep 8 '16 at 13:31
5

Basically ignore everything except your theme folder and custom plugins. sample .gitignore:

wp-admin/
wp-includes/
.htaccess
index.php
license.txt
liesmich.html
readme.html
wp-activate.php
wp-blog-header.php
wp-comments-post.php
wp-config.php
wp-config-sample.php
wp-config-stage.php
wp-config-live.php
wp-config-dev.php
wp-config-production.php
wp-cron.php
wp-links-opml.php
wp-load.php
wp-login.php
wp-mail.php
wp-settings.php
wp-signup.php
wp-trackback.php
xmlrpc.php
config/
wp-content/plugins/
wp-content/mu-plugins/
wp-content/languages/
wp-content/uploads/
wp-content/upgrade/
wp-content/themes/*

# don't ignore the theme you're using
!wp-content/themes/yourthemename

This makes the most sense when used together with composer for installing wordpress and plugins.

| improve this answer | |
  • 3
    if all you want is your theme, then why do you set git at the root of wordpress install at all? – Mark Kaplun Sep 8 '16 at 13:10
  • 2
    because the wordpress root is probably the place where most people keep their composer.json. – skndstry Sep 10 '16 at 4:21
2

This is subjective and depends on what you are trying to achieve. A theme developer may have a different requirement than a plugin developer. Here is a good gist of a bare minimum .gitignore file for a WordPress install.

# -----------------------------------------------------------------
# .gitignore for WordPress @salcode
# ver 20160309
#
# From the root of your project run
# curl -Ohttps://gist.githubusercontent.com/salcode/b515f520d3f8207ecd04/raw/.gitignore
# to download this file
#
# By default all files are ignored.  You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
#
# ignore everything in the root except the "wp-content" directory.
/*
!wp-content/

# ignore everything in the "wp-content" directory, except:
# mu-plugins, plugins, and themes directories
wp-content/*
!wp-content/mu-plugins/
!wp-content/plugins/
!wp-content/themes/

# ignore all mu-plugins, plugins, and themes
# unless explicitly whitelisted at the end of this file
wp-content/mu-plugins/*
wp-content/plugins/*
wp-content/themes/*

# ignore all files starting with . or ~
.*
~*

# ignore node dependency directories (used by grunt)
node_modules/

# ignore OS generated files
ehthumbs.db
Thumbs.db

# ignore Editor files
*.sublime-project
*.sublime-workspace
*.komodoproject

# ignore log files and databases
*.log
*.sql
*.sqlite

# ignore compiled files
*.com
*.class
*.dll
*.exe
*.o
*.so

# ignore packaged files
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# -------------------------
# BEGIN Whitelisted Files
# -------------------------

# track these files, if they exist
!.gitignore
!.editorconfig
!README.md
!CHANGELOG.md
!composer.json

# track these mu-plugins, plugins, and themes
# add your own entries here
!wp-content/mu-plugins/example-mu-plugin/
!wp-content/plugins/example-plugin/
!wp-content/themes/example-theme/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.