Exclude Files from GitHub Pages

July 9, 2023
Anonymous
How can I exclude certain files in my GitHub Pages repo from appearing on the public site?
ChatGPT
ChatGPT

GitHub Pages uses Jekyll, a static site generator, for building websites from repository contents. By default, Jekyll excludes certain files from the build process. As of my last update in 2021, these files are:

  • Any file or directory that starts with the following characters: _, ., #.
  • Any file or directory that ends with the following characters: ~.
  • Any file or directory named node_modules.
  • Any file or directory named vendor.

If you want to exclude other files or directories from your GitHub Pages build, you can do so by specifying them in your _config.yml file with the exclude directive. Here's how to do it:

  1. Open the _config.yml file in the root of your repository (or create it if it doesn't exist).

  2. Add an exclude array to the file. Each item in the array should be a string that specifies a path to a file or directory in your repository. For example, if you want to exclude the private directory and the secret.txt file, you'd write:

    yaml
    exclude: - private/ - secret.txt

Remember that the paths should be relative to the root of your repository.

Here are a few things to keep in mind:

  • This only excludes files from the build process, i.e., they won't be included in the final, built site. The files will still be present in your repository and its history.
  • If you don't want the files to be publicly accessible at all, consider not including them in the repository in the first place. If you've already committed them, you'll need to remove them from your repository's history.
  • You may also want to add these files to your .gitignore file to prevent accidentally committing them in the future.
  • These steps apply to Jekyll sites hosted on GitHub Pages. If your GitHub Pages site isn't using Jekyll, these steps may not apply.
|Terms of use|Privacy policy