GitHub is a popular code hosting platform, but did you know? You can also use it as a free static website hosting platform. In this article, I will show you how to deploy your static website on GitHub.
Step 1: Create a GitHub repository
First, you need to create a new repository on GitHub to store the source code of your website. Make sure to select the Public option to ensure your site is publicly accessible, and add any files or folders you don't want hosted by GitHub (such as node_modules or dist folders) in the .gitignore file.
Step 2: Upload the code to the warehouse
Upload your website code, you can directly upload the local folder, or you can use the command line to submit the code to the warehouse. If you need version control, it is recommended to use the Git tool for submission.
Step 3: Enable GitHub Pages
Enabling GitHub Pages is very simple, provided that there must be an index.html file in your warehouse. In the Settings tab of the repository, scroll down to the GitHub Pages area and select "master branch" as the source, then click the "Save" button.
If your website is developed with a framework such as React, Vue.js, Angular, etc., you may need to place the files generated by the build in the dist folder to ensure that GitHub Pages is enabled correctly.
Step 4: Bind a custom domain name
If you want to bind a custom domain name to a website on GitHub Pages, it is very simple. Just create a new file named CNAME in the root directory of the repository and write your domain name into the file. Then, set up a CNAME record at your domain name service provider to point to your GitHub Pages URL.
Summary
In this article, we briefly introduced how to deploy a static website on GitHub. Overall, this is a very excellent and free option, as GitHub is a very powerful platform that provides high-performance services and stable hosting. If you're looking for an easy, free way to deploy your website, GitHub Pages is definitely worth a try.
The above is the detailed content of How to deploy your website on GitHub. For more information, please follow other related articles on the PHP Chinese website!