Skip to main content
  1. Posts/

Moving Hugo from GitHub Pages to Codeberg Pages

·710 words·4 mins·

Disable GitHub Pages #

Add deprecation notice #

Add deprecation notice in README.md
Let your audience know where you moved

Commit and push it to your repo

Archive repo #

It may be possible that before archiving you’d have to toggle Pages off. Unfortunately I can’t see that option anymore since I’ve disabled it already. If that’s the case and you find the option in repo Settings be sure to do that prior to archiving it.
Archive the repository
Archive your repo to disable Pages

Create Codeberg repo #

Head over to codeberg.org and create an empty repo called pages, you can follow the instructions from https://codeberg.page

Remember that your main/master branch is where you’ll store the generated website only. No markdown, no hugo files nothing. Only the result of site build.

Keep the repository empty for now, we’ll come back to it later.

Move your content #

In your old repo where used to be GitHub Pages set a new git remote

git remote set-url origin https://codeberg.org/<user>/pages.git

# rename main/master branch
git branch -m hugo

# copy compiled website up a dir
cp -vr public ../

# move to your main/master Codeberg branch
git checkout -b main

# bring the compiled website on this branch
cp -vr ../public/** .

# commit and push
git add . ; git commit -m 'initial commit'; git push -u origin main
Replace <user> with your codeberg username. Just set the Codeberg repo as the main remote.

The public/ dir is where your website is dumped after hugo build, depending on your installation some may have it in docs/ dir. Adjust this accordingly.

When you create a new Codeberg repo it defaults to main branch. The name has no importance as long as the repo settings point to it then your website will work perfectly fine.

Automate building your site #

Let’s automate the above steps because repetitive tasks are not worth to be done by humans but rather by 🤖

Request Woodpecker CI access #

Head over to codeberg-ci/request-access and request Woodpecker CI access.

You could also donate to Codeberg to support them paying for the infra.

Configure pipeline #

You should have received your CI access to proceed with these steps.

We basically have to replicate the above steps in your CI and we do that by creating a file at repository root level .woodpecker.yml

You can check out mine as an example .woodpecker.yml

Mine is configured with master (lines 18,20,26) as the main branch. Adjust this accordingly.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
pipeline:
  build:
    image: klakegg/hugo:0.101.0-ext-alpine-onbuild
    commands:
      - hugo mod get -u
      - hugo --gc --buildDrafts --minify
    when:
      event: [pull_request, push]

  publish:
    image: bitnami/git:2
    secrets: [ cbtoken ]
    commands:
      - apt-get update; apt-get install git-lfs --no-install-recommends -y
      - git config --global --add safe.directory $CI_WORKSPACE/public
      - git config --global user.email "woodpecker-bot@no-reply.eu"
      - git config --global user.name "woodpecker-bot"
      - git config --global init.defaultBranch master
      - git config --global lfs.contenttype 0
      - git clone -b master https://codeberg.org/dminca/pages.git
      - cp -a public/* pages/
      - cd pages/
      - git remote set-url origin https://$CBTOKEN@codeberg.org/dminca/pages.git
      - git add --all
      - git commit -m "deploy $CI_COMMIT_SHA"
      - git push -u origin master
    when:
      event: push
      branch: hugo

This pipeline was inspired from codeberg.org/Codeberg-CI/examples.

For the CI runner to have push access to the repo

  • create a token in your Codeberg profile settings
  • head over to https://ci.codeberg.org/repos and locate your repo
  • in repo settings create a Secret CBTOKEN and paste the created token (we’re refering to it on line 12 in .woodpecker.yml)

And that’s all! Congratulations, you’ve successfully migrated from GH Pages to Codeberg Pages.

You can brag on their matrix channel #codeberg.org:matrix.org that you’re all set-up.

Bonus tips #

  • Store your assets (ie. pictures, pdfs) with git-lfs so that your repo doesn’t become more sluggish. I’ve configured mine for pictures .gitattributes, also you can check the README.md for git lfs initial instructions
  • ignore build directory on your hugo branch, for example
Ignoring the build dir in your hugo branch will help keeping your commit history sane and in the event of introducing new content you won’t have to commit a whole chunk of HTML, CSS and all other unrelated stuff, just your markdown file containing your blog post.