📕

#2 Git

⭐

Cours de Julie Chaumard

Why using Git ?

Using Git is an essential best practice, whether you’re working solo or in a team.

  1. Full history of changes
    1. Git keeps track of every version of your code.
    1. You can see who changed what, when, and why.
    1. You can roll back to a previous state of the project if something breaks.
  1. Protection against mistakes
    1. You can experiment in branches without affecting the main project.
    1. If something breaks, you can easily undo or reset the changes.
    1. Git doesn’t delete anything unless you explicitly tell it to.
  1. Structured teamwork
    1. Git allows multiple developers to work on the same project simultaneously.
    1. Each developer works in their own branch, then merges changes safely.
    1. Git helps you resolve conflicts and collaborate efficiently.
  1. Remote backup of your code
    1. By using a Git server (like Gitea, GitHub, GitLab
), you can back up your code online.
    1. If your laptop crashes, your project is still safe and accessible.
  1. Modern workflows: CI/CD, DevOps, automation

    1. Git is the foundation of modern development workflows.
    1. You can automate tasks after every push: testing, deploying, checking security, etc.
    1. It fits perfectly into DevOps and continuous integration pipelines.
  1. Documentation through commits
    1. Your commits become a logbook for the project.
    1. With git log, you can read past commit messages and understand how the project evolved.

A good developer also documents their decisions with meaningful commits.

Gitea

Why Gitea ?

Why use Gitea? (Key Advantages)

  1. Self-hosted on your own server
    Gitea runs on your own infrastructure (VPS, local server, school network).
    Ideal if you want full control over your source code and infrastructure.
    No reliance on third-party cloud providers.
  1. Privacy and data sovereignty
    No data is sent to Microsoft (GitHub) or GitLab Inc.
    Everything is stored on your own server, under your control.
    You manage backups, access, retention policies, etc.
  1. Lightweight, fast, and easy to install
    Gitea is a single binary, very easy to deploy.
    Low memory footprint, fast performance.
    Much simpler than installing full GitLab CE.
  1. Free, open source, and community-driven
    Gitea is fully open source (MIT license) and maintained by an independent community.
    No third-party accounts or subscriptions needed.
    No limits on private repositories (unlike GitHub Free).
  1. Great for learning and teaching

Why not use Gitea?

Gitea vs GitLab

Feature / ToolGitLab CEGitea
Server footprintVery heavy (~4–6 GB RAM minimum)Very lightweight (~100 MB RAM)
Built-in CI/CDYes (very powerful)Not built-in (possible via Drone)
Installation complexityHighVery simple
System administrationComplex (PostgreSQL, Redis, etc.)Minimal (single binary + MySQL/SQLite)
User interfaceVery rich, sometimes overloadedSimple and fast

Installation of Gitea

⏱

https://git.parisweb.art/

User schiller : gitea_school / Sch1ler_git@ (projet@parisweb.art)

(To start the Gitea service :

sudo systemctl stop gitea
sudo -u git GITEA_WORK_DIR=/var/lib/gitea /usr/local/bin/gitea web --port 3001

  1. Which operating system are you using? Debian
  1. Which DBMS do you want to use? MySQL
  1. Will your Gitea instance be installed on the same machine as the database? Same machine
  1. How are you installing Gitea (binary, Docker, system package, or other)? Binary

Prerequisite : git

Git Install on Debian

sudo apt update
sudo apt upgrade
sudo apt install git
git --version
	git version 2.39.5

Create the Gitea Database and a dedicated OS user

sudo mysql -u root -p
CREATE DATABASE gitea CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

CREATE USER 'gitea_user'@'localhost' IDENTIFIED BY '********';

GRANT ALL PRIVILEGES ON gitea.* TO 'gitea_user'@'localhost';

FLUSH PRIVILEGES;

When you launch the Gitea web installation script (http://localhost:3000), you will need to provide the following information:

The Gitea installer will then write this into the file: custom/conf/app.ini.


Create a dedicated system user for Gitea

sudo adduser \
  --system \
  --shell /bin/bash \
  --gecos 'Git Version Control' \
  --group \
  --disabled-password \
  --home /home/git \
  git
  
  // Add the user debian to the git group
  sudo usermod -aG git debian

Install

cd /home/git
sudo wget -O gitea https://dl.gitea.com/gitea/1.24.5/gitea-1.24.5-linux-amd64
sudo chmod +x gitea
ls -l
// Make the binary accessible system-wide
sudo mv gitea /usr/local/bin/gitea

// Create necessary folders
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/

sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

// Create the systemd service (to run Gitea as a service)
sudo nano /etc/systemd/system/gitea.service

	// dd this content
	[Unit]
	Description=Gitea (Git with a cup of tea)
	After=network.target
	
	[Service]
	RestartSec=2s
	Type=simple
	User=git
	Group=git
	WorkingDirectory=/var/lib/gitea/
	ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
	Restart=always
	Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea/
	
	[Install]
	WantedBy=multi-user.target

// Start Gitea
sudo systemctl daemon-reexec
sudo systemctl enable --now gitea

// Check Gitea service
sudo systemctl status gitea





● gitea.service - Gitea (Git with a cup of tea)
     Loaded: loaded (/etc/systemd/system/gitea.service; enabled; preset: enabled)
     Active: active (running) since Sun 2025-08-17 19:15:59 UTC; 28s ago
   Main PID: 55453 (gitea)
      Tasks: 8 (limit: 2290)
     Memory: 97.6M
        CPU: 335ms
     CGroup: /system.slice/gitea.service
             └─55453 /usr/local/bin/gitea web --config /etc/gitea/app.ini

Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:114:showWebStartupMessage() [I] Gitea version: 1.24.5 built with GNU Make 4.3, go1.24.6 : bindata, sql>
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:115:showWebStartupMessage() [I] * RunMode: prod
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:116:showWebStartupMessage() [I] * AppPath: /usr/local/bin/gitea
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:117:showWebStartupMessage() [I] * WorkPath: /var/lib/gitea/
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:118:showWebStartupMessage() [I] * CustomPath: /var/lib/gitea/custom
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:119:showWebStartupMessage() [I] * ConfigFile: /etc/gitea/app.ini
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:120:showWebStartupMessage() [I] Prepare to run install page
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:323:listen() [I] Listen: http://0.0.0.0:3000
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 cmd/web.go:327:listen() [I] AppURL(ROOT_URL): http://localhost:3000/
Aug 17 19:15:59 vps-38339055 gitea[55453]: 2025/08/17 19:15:59 modules/graceful/server.go:50:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 on PID: 55453

// Change the port from 3000 to 3001
// Start Gitea manually from the command line with a specific port (e.g., 3001), without modifying app.ini
sudo systemctl stop gitea

sudo -u git GITEA_WORK_DIR=/var/lib/gitea /usr/local/bin/gitea web --port 3001

Start Gitea service

// Start Gitea manually from the command line with a specific port (e.g., 3001), without modifying app.ini
sudo systemctl stop gitea

sudo -u git GITEA_WORK_DIR=/var/lib/gitea /usr/local/bin/gitea web --port 3001

Browser Install with VPS IP

http://51.210.180.18:3001/

Root location for repositories: /var/lib/gitea/data/gitea-repositories

Git LFS root directory: /var/lib/gitea/data/lfs

Log file path: /var/lib/gitea/log

Gitea base URL: http://51.210.180.18:3001/

Administrator username: gitea_admin

Email: contact@parisweb.art

Pasword : ******

These configuration options will be written into: : /var/lib/gitea/custom/conf/app.ini 

sudo nano /etc/systemd/system/gitea.service

Chnage this line ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
par ExecStart=/usr/local/bin/gitea web --config /var/lib/gitea/custom/conf/app.ini

sudo systemctl daemon-reexec
sudo systemctl restart gitea

sudo netstat -tulnp | grep gitea

Gitea Dashboard url

After the install you open Git via http://51.210.180.18:3001/

Configure a reverse proxy NGINX + HTTPS

/etc/nginx/sites-available/gitea

http://git.parisweb.art/

server {
    listen 80;
    server_name git.parisweb.art;

    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

File configuration /var/lib/gitea/custom/conf/app.ini, after the https configuration

sudo nano /var/lib/gitea/custom/conf/app.ini

Change ROOT_URL = http://51.210.180.18:3001/ with ROOT_URL = http://git.parisweb.art/

[server]
ROOT_URL         = http://git.parisweb.art/

sudo systemctl restart gitea

https

cd /etc/nginx/sites-available
sudo certbot --nginx -d git.parisweb.art
sudo nano /var/lib/gitea/custom/conf/app.ini
Modifier ROOT_URL = https://git.parisweb.art/
sudo systemctl restart gitea

Configure SMTP to be able to send mails

Put code on Gitea

Log in to your instance and create a repository

  1. Go to https://git.parisweb.art
  1. Log in with your account
  1. Click on “+” > “New Repository”
  1. Fill in the information:
    • Repository name: mon-projet
    • Description: optional
    • Visibility: public or private
    • Uncheck “Initialize with README” if you want to push an existing repository
  1. Click on “Create Repository”

For example, the repository created: quiz_konexio https://git.parisweb.art/gitea_school/quiz_konexio

Sync a project between Gitea and a development computer

  1. Clone the project from Gitea
    • Open the terminal and clone the Gitea repository. It will be placed in the current terminal directory.
git clone https://git.parisweb.art/gitea_school/quiz_konexio
  1. Sync local changes to Gitea
// In the terminal, navigate to the repository folder

git add .
git commit -m "Mon message de commit"
git push origin main

To fetch changes made by other people on Gitea

git pull origin main

Use Git in vscode

💚

Agence digitale Parisweb.art
Tout savoir sur Julie, notre directrice de projets digitaux : https://www.linkedin.com/in/juliechaumard/