Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Redirecting GitHub pages after a repository move

Redirecting GitHub Pages after a repository move

The problem

You have a repository, call it alice/repo. You would like to transfer it to the user bob, so it will become bob/repo.

However, you make heavy use of the GitHub Pages feature, so that people are often accessing GitHub will helpfully redirect all of your repository stuff hosted on after the move, but will not redirect the GitHub Pages hosted on

The solution

We solve this by:

  1. Moving the repository, thus breaking all the links
  2. Creating a new user GitHub Pages site for Alice (not project GitHub pages site), at
  3. Adding a file repo/index.html to the user GitHub pages site, which uses <meta http-equiv="refresh"> to redirect to the new URL.

This means that still exists as a working URL, even though the alice/repo repository does not. And it will redirect to the new URL, at

The details

To create a new user GitHub pages site for Alice, Alice will just create a new repository on GitHub named, with a single branch gh-pages. This should work out of the box, although if it doesn't, Alice can check the settings tab for that repository to make sure it's publishing to GitHub Pages.

The file at repo/index.html in the alice/ repository should look like this:

<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to</title>
<meta http-equiv="refresh" content="0; URL=">
<link rel="canonical" href="">

This comment has been minimized.

Copy link

@kaizhu256 kaizhu256 commented Mar 11, 2020

thx, this document helped restore broken-links when moving sql.js to


This comment has been minimized.

Copy link

@k-hinnenkamp k-hinnenkamp commented Apr 3, 2020

When I do this and click on the old link, it downloads the new file instead of redirecting. Any idea what I am doing incorrectly?


This comment has been minimized.

Copy link

@paulirish paulirish commented May 12, 2020

Thanks @domenic! The meta refresh with 0 sec delay is great, and agree that canonical is the move.

I also like to add in some body content, but it's definitely optional.

<body style="text-align: center">
Redirecting to <a href=""></a>

This comment has been minimized.

Copy link

@mukhtharcm mukhtharcm commented Jul 13, 2020

can i just add this one file and get my github pages personal blog to netlify URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.