The great thing about hosting project documentation in a git repository is the ability to deploy it automatically when new changes are pushed. MkDocs makes this ridiculously simple.
If you're already hosting your code on GitHub, GitHub Pages is certainly the most convenient way to publish your project documentation. It's free of charge and pretty easy to set up.
Using GitHub Actions you can automate the deployment of your project documentation. At the root of your repository, create a new GitHub Actions workflow, e.g. .github/workflows/ci.yml, and copy and paste the following contents:
Now, when a new commit is pushed to either the master or main branches, the static site is automatically built and deployed. Push your changes to see the workflow in action.
If the GitHub Page doesn't show up after a few minutes, go to the settings of your repository and ensure that the publishing source branch for your GitHub Page is set to gh-pages.
Your documentation should shortly appear at <username>.github.io/<repository>.
To publish your site on a custom domain, please refer to the MkDocs documentation.
If you prefer to deploy your project documentation manually, you can just invoke the following command from the directory containing the mkdocs.yml file:
If you're hosting your code on GitLab, deploying to GitLab Pages can be done by using the GitLab CI task runner. At the root of your repository, create a task definition named .gitlab-ci.yml and copy and paste the following contents:
Now, when a new commit is pushed to the default branch (typically master or main), the static site is automatically built and deployed. Commit and push the file to your repository to see the workflow in action.
Your documentation is not published under <username>.gitlab.io/<repository> by default since GitLab 17.41. However, if you prefer a cleaner URL structure, such as <username>.gitlab.io/<repository>, you need to adjust your configuration.
To switch from a unique domain to the traditional URL structure, follow these steps:
Locate Your Repository
Go to Settings › Pages in the repository menu.
In the Unique domain settings section, uncheck the box labeled
Use unique domain.
Click Save changes to apply the update.
Now you can reach your documentation under <username>.gitlab.io/<repository>.
Since we can't cover all possible platforms, we rely on community contributed guides that explain how to deploy websites built with Material for MkDocs to other providers: