MkDocs github/ gh-pages deploy trick
Disclaimer:
mkdocs build
doesn't allow the build of the/site
within the same directory, hence the traditional gh-pages deployment settings will fail and it won't deploy your site. (if its a org or user based pages)Hence the follwoing trick should work.
If the output of your MkDocs build is in the /site
folder, you need to push the contents of this folder to the gh-pages
branch of your GitHub repository. However, you should not push the /site
the directory itself but its contents. Here's how you can do it:
Ensure Your Local Repository is Updated:
Make sure your local repository is up to date with the main branch.
Build your MkDocs site using
mkdocs build
. This will update the/site
directory.
Move to the
/site
Directory:Navigate to the
/site
directory in your local repository.
Create a Temporary Git Repository:
Since the
/site
the directory is not a Git repository, you need to initialize it temporarily:
Commit the Changes:
Add and commit the changes in the
/site
directory:
Push to
gh-pages
Branch:Push the contents of the
/site
directory to thegh-pages
branch of your remote repository. Replaceyour-username
with your GitHub username.
Clean Up:
Once you've successfully pushed to
gh-pages
, you can delete the temporary Git repository in the/site
directory:
Configure GitHub Pages:
Go to your repository (
https://github.com/mumbaipy/website
).Click on 'Settings' and scroll down to the 'GitHub Pages' section.
Set the source to the
gh-pages
branch.
Access Your Site:
Your MkDocs site should now be available at
https://mumbaipy.github.io/website/
.
This process ensures that the built HTML files in your /site
directory are pushed to the gh-pages
branch, allowing GitHub Pages to host your MkDocs site. Remember to repeat these steps every time you update your site.
Last updated