# Setting Up Gitea as a Self-Hosted Git Server

If you don't already have a git server (GitLab, GitHub Enterprise, etc.), we recommend [**Gitea**](https://about.gitea.com/products/gitea/) — a lightweight, self-hosted git service that runs in a single Docker container with minimal resources.

## Requirements

* Linux server (Ubuntu 22.04+ recommended)
* 1 GB RAM minimum
* Storage: plan for at least 2x your total IDA database sizes
* Docker

## Step 1: Install Docker

```bash
sudo apt-get update
sudo apt-get install -y docker.io docker-compose-v2
sudo systemctl enable --now docker
```

## Step 2: Configure and Start Gitea

```bash
mkdir -p /opt/gitea
cd /opt/gitea
```

Create a `.env` file with your server's IP address:

```bash
echo 'SERVER_IP=192.168.1.100' > .env
```

Create `docker-compose.yml`:

```yaml
services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=sqlite3
      - GITEA__server__ROOT_URL=http://${SERVER_IP}:3000/
      - GITEA__server__SSH_DOMAIN=${SERVER_IP}
      - GITEA__server__SSH_PORT=2222
      - GITEA__server__DOMAIN=${SERVER_IP}
      - GITEA__server__LFS_START_SERVER=true
      - GITEA__service__DISABLE_REGISTRATION=true
    restart: unless-stopped
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - '3000:3000'
      - '2222:22'
```

Docker Compose reads `.env` automatically. Start it:

```bash
docker compose up -d
```

## Step 3: Initial Setup

Open `http://<SERVER_IP>:3000` in a browser. Fill in the **Administrator Account** at the bottom of the setup page and click **Install Gitea**.

## Step 4: Create a Repository

Log in and click **+ → New Repository**. Give it a name and **do not** initialize it (no README, no .gitignore).

Optionally, create an **Organization** first (**+ → New Organization**) to group repositories under a shared namespace instead of a personal account. For example, with an organization named `ida`, repos are accessible as `git@idbs-repo:ida/my-project.git`.

## Step 5: Configure SSH Access (for clients)

On each client machine that needs to push to Gitea, add an SSH host alias so that regular SSH to the server is not affected.

Edit your SSH config file:

* Linux / macOS: `~/.ssh/config`
* Windows: `C:\Users\<username>\.ssh\config`

Add the following:

```
Host idbs-repo
  HostName 192.168.1.100
  Port 2222
```

This maps the alias `gitea` to the server's SSH on port 2222. Regular `ssh user@<SERVER_IP>` connections remain on port 22.

Add the client's public SSH key in Gitea: **User Settings → SSH / GPG Keys → Add Key**.

Verify access:

```bash
git ls-remote git@idbs-repo:USERNAME/REPO.git
```

## Using a Dedicated Disk

To store repositories on a separate disk (recommended for large repos), mount it before starting Gitea and point the data volume to it:

```bash
# Example: mount /dev/sdb to /mnt/gitea-data
sudo mkfs.ext4 /dev/sdb
sudo mkdir -p /mnt/gitea-data
sudo mount /dev/sdb /mnt/gitea-data

# Add to /etc/fstab for persistence
echo '/dev/sdb /mnt/gitea-data ext4 defaults 0 2' | sudo tee -a /etc/fstab
```

Then update `docker-compose.yml` to use the mounted path:

```yaml
    volumes:
      - /mnt/gitea-data:/data
```

## Maintenance

```bash
cd /opt/gitea

# Update Gitea
docker compose pull && docker compose up -d

# Stop Gitea
docker compose down

# Backup (creates a zip archive)
docker exec -u 1000 gitea gitea dump -c /data/gitea/conf/app.ini
```

All data lives in the `data` volume and survives container restarts and upgrades.

## Troubleshooting

### **SSH connection refused**

Verify the container is running and port 2222 is open:

```bash
docker ps | grep gitea
ss -tlnp | grep 2222
```

### **Push rejected (protected branch)**

Go to the repository **Settings → Branches** and remove branch protection.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hex-rays.com/9.4/add-ons/teams/admin/git-backend-on-premise-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
