-
Notifications
You must be signed in to change notification settings - Fork 0
github pages
This page covers how to set up a basic GitHub Pages site, and do things like redirects on it. This page already assumes you know the basics of using Git and writing webpages.
In short, the steps are:
- create a site, by creating an
username.github.iorepository, then either - add subfolders and pages to that repository
- OR create separate repositories which will deploy to your site
Some terminology:
- Jekyll is the static site generator that underpins GitHub Pages - you'll probably spot references to this
- GitHub Actions is the tool used to deploy your pages to live
Follow the GitHub guidance on Creating a GitHub Pages site.
Site setup in brief:
- Create a new repository for your username or organisation, for example
andrewhick / andrewhick.github.io - Create a readable webpage in the root directory, like an
index.htmlfile - this will appear as your homepage (for example, andrewhick.github.io). If there's noindex.htmlfile, aREADME.mdfile will also work. - Specify that you want to publish from the
mainbranch - see Configuring a publishing source for your GitHub Pages site
Then, under the default configuration, when you make changes to main, a GitHub Action will run to publish your page.
You can then add folders and pages to your github.io repository. For example, if you add a subfolder called pages containing an index.html file, you can access it by going to /pages from your site homepage.
Here is a really basic index.html file you can use to start you off.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello world!</title>
<style>
body { color: #333; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; padding: 40px; }
a { color: #2b8cc4; }
p { font-size: 1.4em; line-height: 1.5em; max-width: 66%; }
</style>
</head>
<body>
<nav><a href="../">Home</a></nav>
<h1>Hello world!</h1>
<p>
Here is my GitHub Pages page.
</p>
</body>
</html>To deploy to GitHub pages from a separate repository, for example pages-test, follow GitHub's guidance on Creating a repository for your site.
- Set up your repository, for example
andrewhick / pages-new - Create a readable webpage in the root directory, like an
index.htmlfile - this will appear as the main page for that subdomain (for example, andrewhick.github.io/pages-new) - Specify that you want to publish from the
mainbranch - see Configuring a publishing source for your GitHub Pages site
If you want to redirect from your page to somewhere else, you can add the following to your home page:
Within the <head> tag:
<meta http-equiv="refresh" content="0; https://www.andrewhick.com/">Within the <body> tag:
<p>If your browser doesn't automatically redirect you, please go to <a href="https://www.andrewhick.com/">AndrewHick.com</a>.</p>If you rename a GitHub repository, any links to the main GitHub repository will automatically redirect.
However, any GitHub Pages sites will not automatically update. You will need to set up a redirect on GitHub Pages yourself.
The following instructions assume that you are renaming a repository from pages-old to pages-new on the site example.github.io, and that you're using the default configurations of GitHub Pages and Actions.
- Within the
pages-oldrepository, prepare a pull request to reflect the name change. For example, make sure that all the content, URLs and the site configuration reflect the new name. - Within the
example.github.iorepository, start working on a pull request. - Add a subfolder for the old address, for example
example.github.io/pages-old. - In this subfolder, add an
index.htmlfile containing a redirect toexample.github.io/pages-newusing the "Set up a redirect" steps above. - Submit the pull requests for review and approval, but don't merge them until you're ready to complete the rename.
- The remaining steps should all be done as close as possible to each other, to minimise downtime.
- On the agreed renaming date, merge both pull requests around the same time.
- Wait a few minutes for GitHub Actions to run in both repositories.
- Check if
example.github.io/pages-oldredirects to/pages-new- however this page won't exist yet, and you will get a 404 error message. - Rename the
pages-oldrepository in GitHub topages-new. - Wait a few minutes for GitHub Actions to deploy the site to the new address.
Then check that:
-
example.github.io/pages-newcontains the updated content that was originally inpages-old -
example.github.io/pages-oldredirects to/pages-new, which now works - if it doesn't work straight away it's worth trying this from a fresh browser or deleting your cache, as the previous version of the page will probably be cached and you won't be able to refresh it due to the redirect -
github.com/example/pages-oldredirects togithub.com/example/pages-new, along with any wikis - internal links within
example.github.io/pages-newstill work
You will also need to update any references to pages-old from elsewhere.