How to migrate multiple static websites from GitHub pages to Codeberg

The official documentation can be found on https://codeberg.page, but I think it is confusing and incomplete if one wants multiple pages with custom domain name.

Warning edit: for now I cannot recommend using Codeberg Pages if one requires reliable uptimes. Codeberg Pages might even become deprecated soon due to unresolved server problems regarding the pages.


Getting the repository on Codeberg

The official documentation instructs to create a repository named "pages" for the static website, but what if one has multiple websites? It's also plain annoying to have such a name for a repository. Anyway, the following steps allows one to have multiple static pages on Codeberg without having to name them "pages", ugh.

  1. Create an account on Codeberg: https://codeberg.org. Then via the top right button click "+ New Repository". Choose whatever repository name, and as "Default Branch" replace main with pages. Click "Create Repository".
  2. Navigate one's computer to the directory of which the content needs to end up in the newly created Codeberg repository. For me that was "/home/…/quitfacebook.org/public/"

Option 1: keep git history

This will preserve the nice graph that shows all the contributions made, and all the file versioning history of course.

      git remote rename origin old-origin-github
      git remote add origin https://codeberg.org/CynicusRex/quitfacebook.git
      git branch -M pages
      git push --set-upstream origin --all
      git push --set-upstream origin --tags
    

Option 2: remove git history

  1. Assuming one still has the hidden .git folder, rename it to .git_BAK or whatever, or delete it.
  2. Open the terminal in that directory and run: git init
    It will probably show the following message: “hint: Using 'master' as the name for the initial branch. This default branch name […] The just-created branch can be renamed via this command: git branch -m <name>”
  3. Run: git branch -m pages
    You see, the repository needn't be named pages, but the branch does. That's great because now one can have multiple pages with distinct names. The official documentation makes it seem as if one is limited to one page.
  4. Run:
    git add .
    git commit -m "first commit"
    git remote add origin https://codeberg.org/CynicusRex/quitfacebook.git
    git push -u origin pages

Domain configurations*

Assuming one has a custom domain name, do the following. If one doesn't, then the official documentation probably suffices.

  1. Add the file ".domains" with the following content to one's local repository and push it to Codeberg, obviously adjusted with one's own domain name:
    quitfacebook.org
    www.quitfacebook.org
    pages.quitfacebook.cynicusrex.codeberg.page
  2. Open one's registrar website, and configure the "Advanced DNS" "host records" as follows:
    Type: A Record, Host: @, Value: 217.197.91.145, TTL: Automatic
    Type: AAAA Record, Host: @, Value: 2001:67c:1401:20f0::1, TTL: Automatic
    Type: CNAME Record, Host: www, Value: quitfacebook.cynicusrex.codeberg.page., TTL: Automatic
    Type: TXT Record, Host: @, Value: quitfacebook.cynicusrex.codeberg.page., TTL: Automatic

All is done. It might take a couple of hours until the domain configurations get updated. Also, don't forget to unpublish your page on GitHub unless you've changed your domain name as well—read on in the latter case.

– – – – –

* Credits to Jan Wildeboer.

Redirecting a GitHub https URL

When changing domain names of a website formerly hosted on GitHub, then merely redirecting on one's registrar website will not redirect https URLs because GitHub pages does not support a .htaccess file nor the SSL plugin. Instead leave unchanged the settings on one's registrar and GitHub, and add a meta refresh tag on every page one wants redirected*.

All done. Enjoy.

– – – – –

* Credits to div72.

—Angelino Desmet; 15 April 2023.

Latest edit: 2024, October 29.

Ψ

Comments

Search for https://fosstodon.org/@stardust/110202336827539450 (fosstodon invite) on one's preferred Mastodon server while logged in, comments appear below.