Git is a version control system developed by Linux Torvalds and is being used by a large number of developers around the world today. Many companies like to use GitHub, which is based on Git version control, and GitHub is now the largest code hosting site in the world. Many large companies are now migrating their code to GitHub. GitHub is a great service, but it has some limitations, one of which is that it doesn’t offer private hosting of code as a free service. In case you want a private repository or need more control, the best way to do it is to run Git on your server.

Common open source Git hosting tools are: GitLab CE, RhodeCode CE, Gitea, Gogs, Phabricator, Redmine, etc. The most popular one is GitLab. The most popular one is GitLab, but since GitLab is very heavy (with many features), it is more suitable for enterprise use, and Gogs or Gitea is recommended here for individual developers.

Difference and connection between Gogs and Gitea

The goal of Gogs is to create the simplest, fastest, and easiest way to build a self-service Git service. Developed in Go, Gogs is distributed as a standalone binary and supports all platforms supported by the Go language, including Linux, Mac OS X, Windows, and ARM. To put it bluntly, he doesn’t write all of the code in Gogs, but he writes most of it, and he is the only one who has the right to decide whether someone else’s code is merged into Gogs.

Gitea is a new branch of the distribution based on Gogs, and the main purpose of Gitea is to bypass the “single maintainer” model of Gogs and let the community decide which new features should be added. So in terms of new features, Gitea has more than Gogs. See A side-by-side comparison of Gitea and other Git hosting tools.

Gogs installation (deployment)

Set up the database.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
sudo mysql -u root -p

SET GLOBAL innodb_file_per_table = ON;
CREATE DATABASE gogsdb;

CREATE USER 'gogsuser'@'localhost' IDENTIFIED BY 'new_password_here';
GRANT ALL ON gogsdb.* TO 'gogsuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

ALTER DATABASE gogsdb CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

FLUSH PRIVILEGES;
EXIT;

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
1
2
3
4
##Then add the lines below and saveā€¦
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic
1
sudo systemctl restart mariadb.service

Installation procedure.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git

cd /tmp
wget https://dl.gogs.io/0.11.91/gogs_0.11.91_linux_amd64.tar.gz
sudo tar xvf gogs_0.11.91_linux_amd64.tar.gz -C /home/git
sudo chown -R git: /home/git/gogs
sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/

sudo systemctl daemon-reload
sudo systemctl enable gogs
sudo systemctl start gogs

sudo systemctl status gogs

sudo nano /etc/nginx/sites-enabled/gogs.biaodianfu.com
1
2
3
4
5
6
7
8
server {
     listen 80;
     server_name gogs.biaodianfu.com;
 
     location / {
         proxy_pass http://localhost:3000;
     }
 }
1
sudo systemctl restart nginx

The user configuration for gogs is changed in custom/conf/app.ini

1
sudo nano /home/git/gogs/custom/conf/app.ini

For Gogs to be able to send notification emails, you need to install Postfix or use some other business mail service such as SendGrid, MailChimp, MailGun or SES.

To enable email notifications, open the configuration file and edit the following line.

1
2
3
4
5
6
[mailer]
ENABLED = true
HOST = SMTP_SERVER:SMTP_PORT
FROM = SENDER_EMAIL
USER = SMTP_USER
PASSWD = YOUR_SMTP_PASSWORD

Restart the Gogs service to enable the application.

1
sudo systemctl restart gogs

Gitea installation (deployment)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
sudo mysql -u root -p
CREATE DATABASE giteadb;
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'new_password_here';
GRANT ALL ON giteadb.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

ALTER DATABASE giteadb CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

FLUSH PRIVILEGES;
EXIT;

## https://dl.gitea.io/gitea/1.12.1

cd /tmp
wget https://dl.gitea.io/gitea/1.12.1/gitea-1.12.1-linux-amd64

sudo mv gitea-1.12.1-linux-amd64 /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea


sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git:git /var/lib/gitea/{data,indexers,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

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

sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea
sudo systemctl status gitea

sudo nano /etc/nginx/sites-enabled/gitea.biaodianfu.com
1
2
3
4
5
6
7
8
server {
     listen 80;
     server_name gitea.biaodianfu.com;
 
     location / {
         proxy_pass http://localhost:3000;
     }
 }
1
sudo systemctl restart nginx

Reference link.