Gitignore your WordPress project

Are you looking for .gitignore for your WordPress project? Your are on right place! Git is very popular versioning system. You can use it for cooperating with your teammates or to track changes for possible rollback. You are committing your code changes on regular bases to make some “history of code”.

If you are just looking for working .gitignore for your project and know how it is working just copy code from this link.

If you want to learn more about Git itself visit official website or check some online tutorials. If you already know Git and using it for your WordPress projects like me, continue reading.

What is .gitignore? #

You will find this file useful if you are not planning to track changes over all files in your project. It is pretty simple. First thing you have to do is to create file with name .gitignore in your root directory. Then you can specify files and folders you want to exclude from change tracking. You can use combinations of exclude and include rules to make it best fit to your needs.

Following example excludes everything except folder /foo/bar/:

/*
!/foo
/foo/*
!/foo/bar

.gitignore and WordPress #

Now we know what .gitignore file is for and lets use it for our WordPress project. You can find tons of examples over the web, but I want to show mine. Everybody is learning all the time so I can update it during the time. You can also have your own better .gitignore for WP, please discuss in comments section then.

Website built using WordPress consist of following main “code areas”:

  • WordPress core
  • Configurations
  • Plugins
  • Themes
  • Uploaded media files

If you want to avoid troubles with future versions of this popular CMS you would rather not touch core area. You should use plugins (like one I created) and themes to make changes on your website. If working with WP for some time, you already know its extensibility and flexibility. To play around with some core functionality WP provides configuration file(s). One you should know is wp-config.php file, which you can use to affect default behavior, specify connection to database and more…

Folder structure of clean WordPress installation
Folder structure of clean WordPress installation

My .gitignore #

So .gitignore file I am using is coming from mentioned WP idea. I want to track files which should modified during development. So it is plugins, themes and configuration files only. Your project can contain more folders not relate to WP. You have to change .gitignore accordingly.

 

Additionally if you are using NetBeans IDE for developing WordPress use additional lines in your .gitignore if you don’t want to track changes in project’s internal files.

 

Tools #

If you are using Git frequently you will find this tool really helpful. It is called gitignore.io and it is very simple to use. You just start typing and it will offer some predefined .gitignore templates based on used IDE, operating system or programming language. I’ve started this way too.

User interface of gitignore.io online tool
User interface of gitignore.io online tool

 

Wish you all happy code tracking and minimum issues leading to rollbacks.

Leave a Reply

Your email address will not be published. Required fields are marked *