Gitignore for Kentico

   —   

One of the first steps taken when starting development on a new project is getting the project into source control. As Git is almost certainly the most popular source control system in use today, I thought it was about time that I share the gitignore file I've honed over the last few years and explain how I decided what to include.

Starting point

Rather than figure out all the basic things to ignore for a normal Visual Studio project, I took the gitignore that Visual Studio generates by default with a new project when you check the "Create new Git repository" option in the New Project window:

New Project window in Visual Studio 2015 with 'Create new Git repository' option checked

This starting point accounts for roughly 80% of the ignore file and should handle most of the basics. However, there are a few additional Kentico-specific items we want to address as well. I also added the Windows ignore rules from GitHub’s gitignore collection.

Kentico conflicts

Kentico has some folders that would be excluded based on the generic Visual Studio ignore (e.g., CMS/CMSAdminControls/Debug). We can handle these conflicts with the ! prefix combined with the * wildcard:

# Include some Kentico folders excluded by rules above
!CMS/CMSAdminControls/*/
!CMS/CMSModules/System/*/

Kentico temporary/environment files

There are a number of different folders and files that Kentico creates for temporary or environment usage automatically. These should be ignored as well:

# Kentico temporary/environment files
CMS/App_Data/AzureCache
CMS/App_Data/AzureTemp
CMS/App_Data/CMSModules/DeviceProfile/logFiftyOne.txt
CMS/App_Data/CMSModules/WebFarm/webfarm.sync
CMS/App_Data/CMSTemp
CMS/App_Data/Persistent
CMS/CMSSiteUtils/Export
CMS/CMSSiteUtils/Import

Smart search indexes

Smart search indexes can create thousands of binary files that are constantly changing. These types of files are clearly not good candidates for source control. However, we do want to include the _StopWords and _Synonyms folders and files in the SmartSearch root folder:

# Ignore all smart search indexes, but not the other system folder contents
CMS/App_Data/CMSModules/SmartSearch/**
!CMS/App_Data/CMSModules/SmartSearch/*/
!CMS/App_Data/CMSModules/SmartSearch/_StopWords/**
!CMS/App_Data/CMSModules/SmartSearch/_Synonyms/**

Starter site files

Unless you are working with one of the starter sites as your base, you most likely don't want to include the extra files that come along with a normal Kentico install. These files are spread out around the CMS directory:

# Starter site resource Files
CMS/App_Data/DancingGoat
 
# Starter site web templates
CMS/App_Data/Templates/CommunitySite
CMS/App_Data/Templates/CorporateSite
CMS/App_Data/Templates/DancingGoat
CMS/App_Data/Templates/EcommerceSite
CMS/App_Data/Templates/IntranetPortal
CMS/App_Data/Templates/PersonalSite
 
# Starter site app themes
CMS/App_Themes/CommunitySite
CMS/App_Themes/CorporateSite
CMS/App_Themes/EcommerceSite
CMS/App_Themes/IntranetPortal*
CMS/App_Themes/PersonalSite
 
# Starter site ASPX templates
CMS/CMSTemplates/CorporateSite
 
# Starter site media libraries
CMS/CommunitySite
CMS/CorporateSite
CMS/DancingGoat
CMS/EcommerceSite
CMS/IntranetPortal
CMS/PersonalSite

Sensitive settings

Even if your repository is only intended for private distribution, you should avoid allowing data that is sensitive or environment-specific or both—such as connection string and hash string salts—from being checked into source control. While some may approach this by not including the web.config file, I find that way of handling the problem to be heavy-handed. There are plenty of other web.config settings and values that are safe and necessary to include in source control so that developers are synchronized and build servers have the necessary information. Instead, add file="AppSettings.config" and configSource="ConnectionStrings.config" to the app settings and connection strings elements respectively. Next, move any sensitive configuration data to those files. It is also recommended that you add template versions of these files for reference. When pulling a fresh copy, the developer should request a copy of any sensitive data from another developer or some other secured location (for more information on this, please read Storing web.configs in Source Control Safely):

# Sensitive settings
AppSettings.config
ConnectionStrings.config

Project media libraries

The last recommendation relates to media libraries. This is more of a preference, but I would generally avoid storing media library content in source control because source control is not really intended for binary files. In order to share media library data from developer to developer, I would recommend a shared storage option, such as Azure Blob Storage or a network share. Regardless, if you choose to exclude the media libraries from source control, the default structure will be in the form of CMS/SiteCodeName:

# Project media libraries (recommend shared file storage)
# e.g. CMS/{SiteCodeName}

Other project specific ignores

As you work on your project, you may come across other things that are specific to your project and need to be excluded. You can add those to the bottom of this ignore using normal gitignore syntax, which is documented on the Git website.

Purposely not ignored items

There are a couple of things that are not ignored on purpose. You may or may not ignore them depending on your thoughts on source control best practices and requirements. First, the Lib folder has not been excluded. This allows the DLLs inside to be included in the repository. I allow this to make it easy to restore the exact version of the Kentico DLLs necessary for the project since the bin directory is excluded based on the Visual Studio rules. When a developer or continuous integration tool gets the repository for the first time, the DLLs can be restored to the bin from Lib directory. Second, there are two .dat files that contain binary data for mobile device detection and IP-based geolocation that are not excluded. These two files are used by Kentico features that you may or may not be using, and your source control tool may give you a warning as they are binary files that are larger than 10MB. In both the case of the lib folder and the .dat files, you are free to ignore them if you wish, but I personally prefer to include them.

Using this in your projects

Please feel free to grab this and use it in your own projects. If you run across any issues or problems, please submit an issue to the GitHub project.

View the full Kentico gitignore on GitHub

Share this article on   LinkedIn

Christopher Jennings

Solution Architect