How I Became More Organized by Learning to [Git] Ignore

Using Git is great for version control for your various projects, but sometimes your repositories become so bloated with testing and development tools that the project becomes difficult to navigate. Not to mention how much more bandwidth is needed to pull and push updates to your code base each time you work on a new feature.

Meet .gitignore

Git gives us a great utility to help us control what we want to track using version control and what we don’t want to include. The .gitignore file specifies the files that you do not want to track. This is useful when you use other processes, such as Composer, to add or compile files for your final project that are not necessary to be tracked for changes.

Using the .gitignore file alone to just arbitrarily specify files that you don’t want to track works okay, if you are the only one working in the project. However, when you start including more and more contributors to the project, that file can get out of control without sticking to a standard.

What I have found helpful is to have commented sections to specify specific tools or directories that I don’t want to track in my repository. This keeps my ignore file better organized and easier to follow when another contributor needs to add another folder or series of files to the list.

By working with WordPress and using Composer to better organize how I update the plugins and themes on my site, I find it much easier to structure my ignore file so that anyone can tell exactly what is not being tracked and what needs to be included.

For example, I don’t want to track every single plugin I have installed but I do want to track my premium or custom plugins so I have more control over their versioning using Git. In my ignore file I would use the following:

# Ignore Plugins Folder

# Do not ignore these Plugins

This allows me to have specific sections to track where I am making sure that certain plugins are included and not having to have a long list of plugins or files that I don’t want to track.

A tool to help

There is a great tool that will help you generate your ignore file based on the kind of project you are working on that includes commented sections like this so that your next project, or even your current project, can be better organized. You can find that tool at GitIgnore.io.

I wouldn’t rely on a generated ignore file entirely. It is a great stepping off point and will help you generate a structure quickly. You should still come up with a structure or standard that works best for you and your contributors for the project you are working on. Not every project is the same, but the practice of organizing your ignore file should remain as consistent as possible. Here is an example of a WordPress + Composer ignore file.

For more information on .gitignore and how the pattern structure is defined, be sure to refer to the documentation. Do you have a standard for your .gitignore process or have tips that you use in your projects that you would like to add? Please drop a comment below!


Have a comment?

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

accessibilityadminaggregationanchorarrow-rightattach-iconbackupsblogbookmarksbuddypresscachingcalendarcaret-downcartunifiedcouponcrediblecredit-cardcustommigrationdesigndevecomfriendsgallerygoodgroupsgrowthhostingideasinternationalizationiphoneloyaltymailmaphealthmessagingArtboard 1migrationsmultiple-sourcesmultisitenewsnotificationsperformancephonepluginprofilesresearcharrowscalablescrapingsecuresecureseosharearrowarrowsourcestreamsupporttwitchunifiedupdatesvaultwebsitewordpress