you need to self-host Github RIGHT NOW!!
Summary
This video provides a comprehensive guide to self-hosting your own GitHub alternative using Gitea. It explains the benefits of self-hosting, including control over your code and avoiding reliance on external services like GitHub. The tutorial walks through setting up a VPS, installing Docker and Docker Compose, configuring Gitea with a Docker Compose file, and accessing the self-hosted instance. It also covers integrating Gitea with AI agents, adding SSH keys for authentication, pushing local code to Gitea, and setting up repository mirroring to GitHub. Finally, it details security measures like disabling password authentication, configuring a firewall, and enabling two-factor authentication for Gitea accounts.
Key Insights
Self-hosting offers control and independence from external platforms like GitHub.
Self-hosting your Git repository solution, such as Gitea, provides complete control over your code and ensures service availability even if platforms like GitHub go down. This independence is a significant advantage for developers.
Local AI agents can interact with self-hosted repositories for a seamless workflow.
The ability for AI agents, especially local ones, to open pull requests on a self-hosted server enhances workflow and control, making it an ideal setup for users prioritizing local operations.
AI agents can create issues, branches, and pull requests on Gitea.
AI agents can be tasked to create issues, work on them by committing to new branches, and subsequently open pull requests directly within the self-hosted Gitea environment.
Configure Gitea to mirror repositories to external platforms like GitHub.
Gitea allows setting up push mirroring to platforms like GitHub, enabling users to maintain a self-hosted copy while keeping a public or secondary backup externally.
Disable password authentication for SSH and enforce key-based login.
To enhance security, password authentication for SSH should be disabled. This is achieved by copying the SSH public key to the server using 'ssh-copy-id' and then configuring the SSH daemon to prohibit password authentication.
Sections
Introduction and Motivation for Self-Hosting
Self-hosting offers control and independence from external platforms like GitHub.
Self-hosting your Git repository solution, such as Gitea, provides complete control over your code and ensures service availability even if platforms like GitHub go down. This independence is a significant advantage for developers.
Gitea is a free, open-source, and easy-to-install alternative to GitHub.
Gitea is presented as a powerful, free, and open-source alternative to GitHub that is surprisingly simple to set up and use, offering a robust solution for managing Git repositories.
Self-hosting enables better code organization and tracking, especially with AI agents.
Utilizing a self-hosted Git repository solution like Gitea is crucial for organizing and tracking code, particularly when working with AI agents, preventing projects from becoming unmanageable. This is a continuation of a previous video on Git.
Local AI agents can interact with self-hosted repositories for a seamless workflow.
The ability for AI agents, especially local ones, to open pull requests on a self-hosted server enhances workflow and control, making it an ideal setup for users prioritizing local operations.
Setting Up the Hosting Environment
Hostinger VPS is recommended for self-hosting Gitea, offering cloud flexibility.
The tutorial utilizes Hostinger's cloud VPS for setting up Gitea, emphasizing its reliability and accessibility for hosting services like a self-hosted GitHub alternative. Setup instructions are also applicable to on-premises solutions.
Installation of Gitea will use Ubuntu and Docker on a fresh VPS.
The process involves setting up a fresh Ubuntu VM or VPS and leveraging Docker and Docker Compose for installing Gitea, as Gitea is designed to function on any system supporting Docker.
Hostinger's Black Friday deal provides a cost-effective way to acquire a VPS.
The video highlights Hostinger's Black Friday promotion as a timely and affordable opportunity to purchase a VPS, specifically recommending the KVM2 plan for its features.
A coupon code 'NETWORKCHUCK' offers additional savings on Hostinger plans.
A discount code, 'NETWORKCHUCK', is provided for viewers to use on Hostinger, further reducing the cost of VPS plans and effectively covering the cost of coffee.
Initial VPS setup involves selecting Ubuntu, location, creating a password, and initiating setup.
The steps for setting up the VPS include choosing the Ubuntu OS (version 20.04 LTS recommended), selecting a server location, creating a strong root password, and completing the setup process.
Connecting to the VPS is done via SSH using the provided command and root password.
After the VPS is provisioned, users connect to it using an SSH client by pasting the generated SSH command into their terminal and entering the root password previously set.
Installing Docker and Docker Compose
Ensure Docker and Docker Compose are installed on the Ubuntu server.
Before installing Gitea, it's necessary to have Docker and Docker Compose installed. The video provides commands to add Docker's official APT repository and install the necessary packages.
Docker and Docker Compose are essential tools for containerizing applications.
Docker enables containerization, allowing applications to run in isolated environments, while Docker Compose simplifies the management of multi-container Docker applications, both being crucial for Gitea's deployment.
Configuring and Installing Gitea with Docker Compose
Create a directory and environment file for Gitea configuration.
A dedicated directory named 'Gitea' is created, and within it, a '.env' file is established to store environment variables such as database password, Gitea domain, and ACME email for SSL.
Generate a secure random password for the Gitea database.
The command 'openssl rand -hex 24' is used to generate a strong, random hexadecimal string which serves as the database password, stored in the .env file.
Define the Gitea domain using the VPS's default DNS name or a custom IP address.
The 'GITEA_DOMAIN' variable in the .env file is set to the Hostinger-provided DNS name for the VPS, or alternatively, the server's IP address if self-hosting locally.
Use official Gitea Docker Compose configuration for PostgreSQL.
A 'docker-compose.yaml' file is created and populated with the official Gitea Docker Compose configuration, which includes settings for a PostgreSQL database.
An override file customizes Docker Compose settings for Gitea's database and domain.
A 'docker-compose.override.yaml' file is used to apply specific configurations, including setting the database password, domain, and port overrides, ensuring Gitea uses the defined environment variables.
Start Gitea services using Docker Compose in detached mode.
The command 'docker compose up -d' is executed to launch Gitea and its associated services (like the database) in the background, ensuring they run persistently.
Monitor Gitea startup and Let's Encrypt certificate generation via logs.
The command 'docker compose logs -f server' allows real-time monitoring of Gitea's startup process, including the successful acquisition of a Let's Encrypt SSL certificate for HTTPS access.
Initial Gitea Configuration and Setup
Access Gitea via HTTPS using the server's domain or IP address.
After Gitea starts, navigate to 'https://your-domain-or-ip' in a web browser to begin the initial setup process.
Review and confirm settings like database connection and domain name.
The initial configuration screen displays settings derived from the Docker Compose and .env files, such as the website URL. Most settings can be confirmed as they are pre-configured.
Disable self-registration and enforce login for viewing pages.
For security, it's recommended to disable 'Allow self-registration' and enable 'Require sign-in to view pages' in the Gitea settings to prevent unauthorized access.
Create an administrator account for managing Gitea.
An administrator account is created during the setup process to provide full access and control over the Gitea instance.
Install Gitea to finalize the setup process.
Clicking 'Install Gitea' completes the initialization, directing the user to the Gitea login page.
Using Gitea: Repositories and SSH Authentication
Create a new repository within your self-hosted Gitea instance.
Navigate to the top right corner of the Gitea interface, click the '+' icon, and select 'New repository' to create a repository, setting its name and visibility (private by default).
Add your SSH public key to Gitea for secure authentication.
Generate an SSH key pair if one doesn't exist ('ssh-keygen -t ed25519'). Copy the public key ('~/.ssh/id_ed25519.pub'), go to Gitea's user settings, navigate to 'SSH and GPG keys', and add the key.
Verify SSH key by signing a token provided by Gitea.
Gitea requires verification of the SSH key by having the user sign a specific token using their SSH private key in the terminal, confirming the key is correctly associated with the account.
Test SSH connection to confirm successful authentication.
Use an SSH command like 'ssh your-username@your-gitea-domain -p 222' (using a custom port if configured) to verify that authentication with the added SSH key is successful.
Add Gitea as a Git remote to your local repository.
If migrating from GitHub, rename the existing 'origin' remote to 'github' ('git remote rename origin github'). Then, add the Gitea repository as the new 'origin' using its SSH URL ('git remote add origin git@your-gitea-domain:user/repo.git').
Push your local code to the Gitea repository.
After setting up the remote, use 'git push -u origin main' (or your default branch name) to upload your local code to the newly configured Gitea repository.
Integrating AI Agents with Gitea
Create a bot user identity on Gitea for AI agents.
Within Gitea's site administration, create a new user account with the 'bot' user type to represent AI agents interacting with the repository.
Generate an access token for the bot user to grant permissions.
After creating the bot user, generate an access token within Gitea that grants the necessary read/write permissions for the agent to interact with repositories.
Configure the Gitea MCP (Machine Communication Protocol) server for AI integration.
Download the Gitea MCP server binary from its releases page. Configure it with environment variables for the Gitea host URL and the generated access token.
Add the MCP server to your AI development environment (e.g., Claude Code).
Use the AI tool's command-line interface to add the configured Gitea MCP server, specifying its name and the path to the downloaded MCP server file.
AI agents can query Gitea for repository information like open issues.
Once integrated, AI agents can interact with Gitea, for example, by asking how many issues are open on a specific repository.
AI agents can create issues, branches, and pull requests on Gitea.
AI agents can be tasked to create issues, work on them by committing to new branches, and subsequently open pull requests directly within the self-hosted Gitea environment.
Add AI bot users as collaborators to repositories to enable pull request creation.
To allow AI bots to open pull requests, they must be added as collaborators to the specific repository they need to interact with via Gitea's repository settings.
AI-generated code changes can be merged directly into the repository after review.
Pull requests created by AI agents can be reviewed and merged directly within Gitea, similar to GitHub's workflow, streamlining the development process.
Local AI models can perform complex tasks like writing entire story endings on Gitea.
The tutorial demonstrates using local AI models (like Gemma 431B via Claude Code) to complete complex tasks assigned via Gitea issues, showcasing powerful local AI capabilities.
Repository Mirroring and Advanced Features
Configure Gitea to mirror repositories to external platforms like GitHub.
Gitea allows setting up push mirroring to platforms like GitHub, enabling users to maintain a self-hosted copy while keeping a public or secondary backup externally.
Generate a Personal Access Token on GitHub for mirroring authentication.
To enable mirroring from Gitea to GitHub, a Personal Access Token (PAT) with appropriate repository permissions is generated in GitHub's developer settings.
Set up mirror sync settings in Gitea repository settings.
Within Gitea's repository settings, under 'Mirror settings', users input their GitHub username, the generated PAT as the password, and the remote repository URL for the push mirror.
Synchronize changes immediately after enabling mirroring.
After configuring the mirror settings, users can manually synchronize the repository to push existing local changes and ensure the mirrored copy on GitHub is up-to-date.
Local AI on Gitea provides a secure and cost-effective alternative to cloud AI.
The ability to run AI tasks locally against a self-hosted Gitea instance reduces reliance on cloud resources, offering greater privacy, control, and potentially lower costs.
Securing Your Self-Hosted Gitea Instance
Disable password authentication for SSH and enforce key-based login.
To enhance security, password authentication for SSH should be disabled. This is achieved by copying the SSH public key to the server using 'ssh-copy-id' and then configuring the SSH daemon to prohibit password authentication.
Configure SSH daemon to only permit root login via SSH keys.
Editing the SSH daemon configuration file to set 'PasswordAuthentication no' and 'PermitRootLogin prohibit-password' ensures that root login is exclusively possible using SSH keys.
Implement firewall rules using UFW for security.
Ubuntu's Uncomplicated Firewall (UFW) is used to set up rules, including rate limiting for SSH port 22 to prevent brute-force attacks, and allowing necessary ports like 80, 443, and Gitea's custom SSH port (e.g., 222).
Enable Two-Factor Authentication (2FA) for Gitea user accounts.
Gitea supports 2FA for enhanced account security. Users can enroll using authenticator apps (like Google Authenticator) and should securely store the provided single-use recovery keys.
Consider using Passkeys for even stronger authentication in Gitea.
Gitea also supports Passkey authentication, offering a more modern and secure alternative to traditional passwords and 2FA.
Conclusion
Gitea offers a powerful and trustworthy self-hosted alternative to GitHub.
The video concludes by recommending Gitea as a reliable and enjoyable self-hosted solution for managing Git repositories, empowering users with greater control over their code.
Self-hosting provides a sense of freedom and control over code.
The speaker encourages viewers to try self-hosting with Gitea and shares their positive experience regarding the freedom and control it offers over their development workflow.
Ask a Question
*Uses 1 Wisdom coin from your coin balance











