Using a service like DeployHQ with Git or another SCM is great for helping streamline your deployment process. However, you may find that there are some files you keep in your repository, or fetch via the build pipeline that don't want to upload to your server, such as dependencies that you're using to compile assets.
In DeployHQ, we have a feature that is designed with this use case in mind. Within any project, you can set up a list of Excluded Files, which are simply paths to one or more files that DeployHQ will check through and then ignore files that match.
Think of excluded files as a blacklist to stop anything in that list from being modified during the deployment.
Adding an Excluded File
Adding an excluded file is very simple. Head to any project, then click the Excluded Files link on the left hand side, followed by the New Excluded Files button to the top-right:
Enter the file path, relative to how the file is found in your repository then, optionally, choose one of more specific servers to apply the rule to. This is useful if you want to deploy the file to your production server, but not your development server.
Click Create Excluded File, then after that any deployments you run to a server it's applied to will ignore anything that matches.
The Excluded File rules can be applied in a number of different ways, beyond just matching a specific file. You can also set up wildcards to exclude files with a certain extension, or within a specific directory.
For example, you might want to stop all
yml files from being deployed. Add the following two rules to ignore any yml file both within your root directory, and any subdirectory:
You'll notice the
** in the second rule - because the feature uses pattern matching this means that anything in the path before the leading slash will be matched, so any yml file in a subdirectory will be ignored.
If you want to ignore a whole directory, you can again add two rules that might look like so:
That will ignore
node_modules itself, along with any files, or subdirectories found within it.
As well as being able to add excluded file rules to a project, you can also commit the rules to your repository using a
If you're familiar with
.gitignore it works in very much the same way. Simply add the file to your repository's root directory, and place each rule on a new line.
*.yml **/*.yml node_modules node_modules/**
Then, once the file has been committed and pushed to your repository, DeployHQ will detect it and stop any files in exactly the same way. Just remember that the file must be present in the commit you're deploying to, otherwise DeployHQ won't see it when it checks out the repository to deploy it.
We hope this guide has been useful in outlining how to stop files being deployed when you don't want them to be, do let us know if you have any questions.