Spacebear Blog

How to deploy Gitea repositories to Netlify

Published: July 28, 2020

This tutorial assumes you have a Netlify account, the Netlify CLI already installed, and access to a Gitea instance that can receive SSH clone requests from the public internet.

To start you’ll need to go into your existing (or a new) git repo. Then you’ll need to tell Netlify about your repo. The --manual flag in the command below is to let netlify know you are using another Git hosting service. If you haven’t already authorized the netlify CLI you will be prompted to login via webbrowser.

$ netlify init --manual

When running the above, you’ll be prompted with several questions. Follow the instructions and choose what is appropriate for you (new site, belong to default team, and random name are the default choices).

Once the site is created it’ll give you an SSH Public key that you need to set as a deploy key in your Gitea repository. This SSH key will need to be copied to the deploy key section of your repository section (example URL: https://git.example.com/username/reponame/settings/keys).

Now, you’ll need to tell Netlify how to build your site and where the generated files are located, assuming you are using hugo to generate your site, the command would be hugo build and the directory would be public.

Finally you’ll be given a URL for a webhook (example: https://api.netlify.com/hooks/1a79a4d60de6718e8e5b326e338ae533), and you take this URL and create a new webhook for your repo, and have it trigger on all git push events. The URL to configure new webhooks is https://git.example.com/username/reponame/settings/hooks/gitea/new

Now whenever you do a git push to your git repo Netlify will start a build/deploy of your new site.

Future Steps

This is just a super basic way of connecting a git repo with Netlify, you can continue to configure your Netlify site settings by adding custom domains, and more!