Guide / Tutorial

Self-Host Your Own GitHub with Gitea and Let AI Agents Work Your Issues

Gitea is a free, open-source alternative to GitHub that you can run on your own server in about ten minutes. This guide covers the Docker install, pushing code over SSH, a bot account plus the Gitea MCP server so Claude Code (or a local model) can work your issues and open pull requests, a push mirror to GitHub, and the basic hardening every internet-facing server needs.

Claude CodeThis guide is about Claude Code.
Self-Host Your Own GitHub with Gitea and Let AI Agents Work Your Issues

A step-by-step path to a private Git server you control: install Gitea with Docker, push your code over SSH, give an AI agent its own bot account and the Gitea MCP server so it can work issues and open pull requests, keep a public mirror on GitHub, and lock the server down.

Reading map

  • Part I — Install Gitea: why self-host, where to run it, and the Docker setup with a database password, two compose files and automatic HTTPS (sections 1 to 4).
  • Part II — Push your code: a repository, SSH keys and moving an existing GitHub repo (sections 5 to 7).
  • Part III — Let AI agents work your issues: a bot account, the Gitea MCP server in Claude Code, issues as a to-do list, a local model and a push mirror (sections 8 to 12).
  • Part IV — Lock it down: keys-only SSH, a firewall and two-factor sign-in (sections 13 to 15).
  • A comparison table, a final perspective, a quick reference and a FAQ close the guide.

Why This Matters

If you build with AI, your agents produce a lot of code: features, fixes, experiments. Without a Git remote, that work is hard to track, review and undo. GitHub solves this, but it also means your code lives on someone else’s servers, and when GitHub has an outage, so do you.

Gitea gives you the familiar GitHub workflow (repositories, issues, pull requests, merges) on a machine you control. And because it supports the Model Context Protocol through an official MCP server, AI agents such as Claude Code can use it the same way you do: read an issue, create a branch, commit and open a pull request for you to review. With a local model, the whole loop never touches a cloud AI.

Your code, your server, your agents.

Part I — Install Gitea

1. Why self-host

Two reasons stand out. First, independence: no more waiting on GitHub’s status page, and no third party controlling your code. Second, structure for AI-assisted work: a Git server is the place where you and your agents organise and track what gets built, with issues as the to-do list and pull requests as the review step.

Two reasons to run your own Git server.
Two reasons to run your own Git server.

2. Where to run it

Gitea runs on anything that runs Docker. Two common choices:

  • A cloud server (VPS) with a fresh Ubuntu install: always on and reachable by you and your agents from anywhere.
  • A virtual machine in a home lab: everything stays on your network; use the machine’s local IP address instead of a domain.

On Ubuntu, install Docker and the Docker Compose plugin from Docker’s official apt repository, following Docker’s own instructions.

3. Prepare the folder and secrets

Create a folder, generate a strong database password and store your settings in a .env file:

mkdir gitea && cd gitea
openssl rand -hex 24              # copy the output: your database password
nano .env

DB_PASSWORD=<the generated password>
GITEA_DOMAIN=<your domain, or the server's IP address>
ACME_EMAIL=<your email, for the HTTPS certificate>

The .env file keeps secrets out of the compose files. Never commit it to a repository.

The folder setup: one password, one domain, one email.
The folder setup: one password, one domain, one email.

4. Two compose files, one command

  • docker-compose.yml: copy the PostgreSQL example from Gitea’s installation documentation unchanged.
  • docker-compose.override.yml: your own additions, such as the database password and domain from .env and the port mapping (Git over SSH on port 222, so port 22 stays free for logging in to the server itself).

Keeping your changes in an override file means you can replace the official file later without losing them. Start everything in the background and watch the logs:

docker compose up -d
docker compose logs -f server     # watch Gitea obtain its Let's Encrypt certificate

Then open domain>. The initial configuration page is mostly pre-filled from your files. Change two settings before you click Install Gitea:

  1. Only administrators can create user accounts (turn off self-registration).
  2. Require sign-in to view pages.

Add your administrator account, install, and you have your own GitHub.

Gitea's initial configuration: restrict account creation and require sign-in.
Gitea’s initial configuration: restrict account creation and require sign-in.

Part II — Push Your Code

5. Create a repository

Click the plus menu, then New Repository, name it and create it. Visibility matters less than on GitHub: nobody sees anything on your server unless you invite them.

6. Sign in with an SSH key

Your computer authenticates to Gitea with an SSH key:

ssh-keygen -t ed25519                   # only if you do not have a key yet
cat ~/.ssh/id_ed25519.pub               # the PUBLIC key: copy this

In Gitea, open your avatar menu, then Settings, SSH / GPG Keys, Add Key, and paste the public key. Gitea then asks you to verify it by signing a token; it shows the exact command for macOS, Linux, PowerShell or CMD, and you only fill in the path to your private key. Test the connection:

ssh -T -p 222 git@<your-domain>

A successful test greets you by name and confirms the key.

SSH key setup and the connection test.
SSH key setup and the connection test.

7. Move an existing GitHub repository

If the project already lives on GitHub, keep that remote under a new name and make Gitea the default:

git remote -v                              # shows origin → GitHub
git remote rename origin github
git remote add origin <the repo's SSH address from Gitea, port 222>
git push -u origin main

Refresh the repository page and your history is there. git push github main still updates GitHub when you want it to (or use a mirror, section 12).

Part III — Let AI Agents Work Your Issues

8. Give the agent its own account

Do not let an agent act as you. In Site Administration, open Identity & Access, then User Accounts, and create a new user with the user type bot (the walkthrough names it Leon). Then generate an access token for that account. Treat the token like a password: it is everything the agent needs to act on your server.

Separate bot accounts make every agent action visible in the history (“Leon opened pull request #2”) and let you limit what the agent can touch.

9. Connect Claude Code with the Gitea MCP server

Gitea publishes an official MCP server. Download the release for your operating system from its repository’s Releases page, unpack it, and register it with Claude Code from inside your project folder:

claude mcp add gitea \
  -e GITEA_HOST=<your Gitea address> \
  -e GITEA_ACCESS_TOKEN=<the bot's token> \
  -- <path to the downloaded gitea-mcp binary>

Start Claude Code and test with a simple request: “use the Gitea MCP and tell me how many issues are open on my repository.” The answer comes back through Gitea, signed in as the bot account. Even a small, fast model can do this.

Registering the Gitea MCP server in Claude Code.
Registering the Gitea MCP server in Claude Code.

10. Issues as the agent’s to-do list

Issues are the natural way to hand work to an agent. Create one in the repository with a clear title and description, then instruct the agent:

Work issue #1 on <repo> in Gitea: commit on a branch and open a pull request.

The first run in the walkthrough failed at the last step: the bot was not a collaborator, so it could push a branch but not open the pull request. Fix it under the repository’s Settings, Collaborators, add the bot, and run again. The pull request appears; review it and merge it exactly as on GitHub.

11. Use a local model

The same workflow works with local models. Claude Code can be pointed at a locally running model; in the walkthrough, Gemma 4 31B picked up another issue, wrote the change on a new branch and opened its own pull request. With Gitea on your own server and the model on your own hardware, no cloud AI service sees the code.

12. Keep a public copy with a push mirror

Self-hosting does not mean giving up GitHub. For a portfolio or an open-source project, keep GitHub as a public mirror:

  1. On GitHub: Settings, Developer settings, Personal access tokens, and create a token with access to the repository.
  2. In the Gitea repository: Settings, scroll to Mirror Settings, enter the GitHub repository address, your GitHub username and the token as the password, and tick sync when commits are pushed.
  3. Click Synchronize now to test it.

Every push to Gitea now updates GitHub automatically.

Gitea as the main copy, GitHub as the public mirror.
Gitea as the main copy, GitHub as the public mirror.

Part IV — Lock It Down

A server on the internet is probed constantly. Three measures cover the basics.

13. SSH keys only

Copy your key to the server, confirm you can log in without a password, then disable password logins with a small drop-in file:

ssh-copy-id root@<your-server>                 # from your computer

# /etc/ssh/sshd_config.d/<lockdown>.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password

systemctl reload ssh

Test from a second terminal before you close your session: a machine without your key should now be refused.

Keys-only SSH.
Keys-only SSH.

14. A firewall

Ubuntu’s built-in UFW is enough:

ufw limit 22/tcp                # rate-limit repeated login attempts
ufw allow 80,443,222/tcp        # web (HTTP/HTTPS) and Git over SSH
ufw enable
ufw status

Make sure port 22 is allowed (here via limit) before enabling the firewall, or you lock yourself out.

15. Two-factor sign-in

In Gitea, open Settings, Security and enroll two-factor authentication with an authenticator app (passkeys are also available). Store the single-use recovery codes somewhere safe, then sign out and back in to confirm it works.

Gitea vs GitHub

Gitea (self-hosted) GitHub
Who runs it You, on your server or VM GitHub (Microsoft)
Cost Free software; you pay for the machine Free tiers and paid plans
Outages Yours to manage Outside your control
Visibility Private unless you invite people Public or private per repo
AI agents Gitea MCP + a bot account; works with local models GitHub’s own integrations and MCP
Public reach Via a push mirror to GitHub Built in

Final Perspective

The most useful idea in this setup is not self-hosting by itself. It is treating an AI agent like a teammate with its own account: it receives work as issues, does it on a branch and hands it back as a pull request that you review and merge. That keeps every change visible and reversible, whoever (or whatever) wrote it.

Gitea makes that workflow cheap to own. Ten minutes with Docker gives you the server, an MCP server gives your agents access, and a mirror keeps GitHub for the public side. The security steps are short but not optional: an internet-facing server with password logins and open ports will be found.

Quick Reference

Task Command or place
Database password openssl rand -hex 24
Start Gitea docker compose up -d
Watch the certificate docker compose logs -f server
First-run settings Admin-only accounts, sign-in required
SSH key ssh-keygen -t ed25519, paste the .pub key in Settings, SSH / GPG Keys
Test SSH ssh -T -p 222 git@<your-domain>
Move from GitHub git remote rename origin github, git remote add origin …, git push -u origin main
Agent identity Site Administration, User Accounts, type bot, access token
Connect Claude Code claude mcp add gitea -e GITEA_HOST=… -e GITEA_ACCESS_TOKEN=… -- <gitea-mcp>
Bot can’t open a PR Repository Settings, Collaborators, add the bot
Public copy Repository Settings, Mirror Settings, push mirror with a GitHub token
Harden keys-only SSH, ufw limit 22/tcp, ufw allow 80,443,222/tcp, 2FA

FAQ

Is Gitea free?

Yes. Gitea is free, open-source software. You pay only for the machine it runs on, which can be a small cloud server or a computer you already own.

Can I run Gitea at home instead of in the cloud?

Yes. Any machine or virtual machine that runs Docker works. Use its local IP address instead of a domain; agents on your network can reach it, and nothing is exposed to the internet unless you choose to.

Why does Git use port 222 instead of 22?

Port 22 is already used by the server’s own SSH login. Mapping Gitea’s built-in SSH to port 222 keeps the two apart, so you can lock down server logins without affecting Git.

How does Claude Code talk to Gitea?

Through Gitea’s official MCP server. You register it with claude mcp add, passing your Gitea address and a bot account’s access token as environment variables. Claude Code can then read issues, create branches and open pull requests.

Why did my agent fail to open a pull request?

Usually because its bot account is not a collaborator on the repository. Add it under the repository’s Settings, Collaborators, then run the task again.

Can I keep using GitHub?

Yes. Either keep GitHub as a second remote and push to it when you want, or set up a push mirror in the Gitea repository so every push is copied to GitHub automatically.

Further Reading

  • Gitea’s documentation: installation with Docker, SSH container passthrough, mirrors and two-factor authentication.
  • The Gitea MCP server’s repository and release notes.
  • On AIBotRadar: more guides on Claude Code, MCP and AI coding agents.

Commands are redrawn with placeholders; use your own domain, passwords and tokens. Versions, menus and options change; check Gitea’s current documentation before relying on them.

Claude Code GUIDES

More Claude Code guides

Continue with practical guides about Claude Code.

View all AI Coding guides