*** GUIDE ***Forgejo - Powerful Self-Hosted Git Service

What is Forgejo?

Forgejo is a self-hosted Git service that gives developers the power to manage their projects independently, without relying on proprietary platforms. By hosting Forgejo yourself, you gain full control over your development environment, which you can customize to meet your team’s needs. Whether it’s integrating with other tools, enhancing your workflow, or ensuring the security of your software development, Forgejo provides a scalable, secure, and lightweight platform for collaboration.

Created through the joint efforts of Codeberg e.V., Forgejo is a community-driven project that champions freedom and transparency. As a fully open-source solution, it will always remain free from commercial interests. You can either create an account on an existing instance or self-host your own, giving you maximum flexibility and control. With Forgejo, developers have a solution built on the principles of security, scalability, privacy, and openness, empowering you to work together without barriers.

Key Features of Forgejo

  • Easy Setup: Install Forgejo in just minutes using either a binary installer or Docker for greater flexibility.
  • Cross-Platform Compatibility: Forgejo supports Windows, macOS, Linux, ARM, and more, ensuring wide accessibility.
  • Efficient Performance: With its lightweight design, Forgejo runs smoothly on resource-constrained devices like Raspberry Pi.
  • Community-Driven: As an open-source project, Forgejo welcomes contributions from its community, allowing users to shape its future.

Installing Forgejo with Docker Compose

To ensure a secure installation, it’s recommended that you set up a Cloudflare tunnel or NGINX domain beforehand. Once done, you can access Forgejo’s web interface by pointing your domain to port 3000.

Below is a Docker Compose stack to help you install Forgejo on your server. If you’re new to self-hosting, be sure to check out guides on getting started. Always refer to Forgejo’s release notes for the latest version.

version: "3"

networks:
  forgejo:
    external: false

services:
  app:
    image: codeberg.org/forgejo/forgejo:8
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - FORGEJO____APP_NAME=${APP_NAME}
      - FORGEJO____APP_SLOGAN=${APP_SLOGAN}
      - FORGEJO__database__DB_TYPE=postgres
      - FORGEJO__database__HOST=db:5432
      - FORGEJO__database__NAME=${DB_NAME}
      - FORGEJO__database__USER=${DB_USER}
      - FORGEJO__database__PASSWD=${DB_PASSWORD}
      - FORGEJO__server__SERVER_LANDING_PAGE=${LANDING_PAGE}
      - FORGEJO__mailer__ENABLED=${MAILER_ENABLED}
      - FORGEJO__mailer__FROM=${MAILER_FROM}
      - FORGEJO__mailer__PROTOCOL=smtps
      - FORGEJO__mailer__SMTP_ADDR=${MAILER_SMTP_ADDR}
      - FORGEJO__mailer__SMTP_PORT=${MAILER_SMTP_PORT}
      - FORGEJO__mailer__USER=${MAILER_USER}
      - FORGEJO__mailer__PASSWD=${MAILER_PASSWD}
      - FORGEJO__email.incoming__ENABLED=${EMAIL_INCOMING_ENABLED}
      - FORGEJO__email.incoming__REPLY_TO_ADDRESS=${EMAIL_INCOMING_REPLY_TO_ADDRESS}
      - FORGEJO__email.incoming__HOST=${EMAIL_INCOMING_HOST}
      - FORGEJO__email.incoming__PORT=${EMAIL_INCOMING_PORT}
      - FORGEJO__email.incoming__USERNAME=${EMAIL_INCOMING_USERNAME}
      - FORGEJO__email.incoming__PASSWORD=${EMAIL_INCOMING_PASSWORD}
      - FORGEJO__service__ENABLE_NOTIFY_MAIL=true
      - FORGEJO__email.incoming__USE_TLS=${EMAIL_INCOMING_USE_TLS}
    restart: always
    networks:
      - forgejo
    volumes:
      - /docker/forgejo/forgejo:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "${PORT_HTTP}:3000"
      - "${PORT_SSH}:22"
    depends_on:
      - db
    env_file:
      - stack.env  

  db:
    image: docker.io/library/postgres:16-alpine
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      start_period: 20s
      interval: 30s
      retries: 5
      timeout: 5s
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
    networks:
      - forgejo
    volumes:
      - /docker/forgejo/postgres:/var/lib/postgresql/data
    env_file:
      - stack.env

stack.env file

APP_NAME=Your App Name
APP_SLOGAN=A painless, self-hosted Git service
PORT_HTTP=85
PORT_SSH=2223
DB_NAME=YourDB name
DB_USER=YoudDbUser
DB_PASSWORD=tAXGpCR5LcGrX0vF
SERVER_LANDING_PAGE=login
MAILER_ENABLED=true
MAILER_FROM=
MAILER_SMTP_ADDR=
MAILER_SMTP_PORT=465
MAILER_USER=
MAILER_PASSWD=
EMAIL_INCOMING_ENABLED=true
EMAIL_INCOMING_REPLY_TO_ADDRESS=forgejo+%{token}@hhf.technology
EMAIL_INCOMING_HOST=
EMAIL_INCOMING_PORT=993
EMAIL_INCOMING_USERNAME=
EMAIL_INCOMING_PASSWORD=
EMAIL_INCOMING_USE_TLS=true

Important: For production environments, always change the default database credentials (username and password). The example above uses default settings for simplicity, but ensure you update them before deploying your setup live.


Completing the Installation

After setting up your Docker Compose stack, navigate to your domain to access the Forgejo installation page. Here, you’ll need to fill in the required details to complete the setup. Once you’ve submitted the form, click the “Install” button to finalize the process. After installation, you will be redirected to the main Forgejo dashboard, where you can start creating repositories, setting up organizations, and managing your Git workflow.


Final Thoughts

By choosing Forgejo, you’re not just installing another Git service—you’re joining a community that values open-source principles. Forgejo offers you the freedom to code and collaborate without restrictions. Its flexible, modular architecture allows you to adapt it to your unique workflow, and your contributions will help shape the future of the project. With Forgejo, you control your development environment while fostering transparency and collaboration.

1 Like