Operations 5 min read

Setting Up a Simple Gogs Git Server with Systemd on Linux

This guide walks through installing Gogs, creating a start‑up script, configuring a systemd service, launching the server, checking its status, creating repositories via the web UI or command line, and pushing code with saved credentials, all on a Linux host.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Setting Up a Simple Gogs Git Server with Systemd on Linux

First, create a start‑up script for Gogs at /usr/local/gogs/start.sh with the following content:

#!/bin/bash
/usr/local/gogs/gogs web > /tmp/gogs.log 2>&1

Make the script executable:

chmod +x /usr/local/gogs/start.sh

Next, define a systemd unit file /usr/lib/systemd/system/gogs.service :

[Unit]
Description=gogs
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/gogs/start.sh
User=root

[Install]
WantedBy=multi-user.target

Reload the daemon and start the service:

systemctl daemon-reload
systemctl restart gogs

Verify that Gogs is listening (default port 3000) using netstat -nltp or similar tools.

Check the server log for successful startup:

tail -f /usr/local/gogs/log/gogs.log

After confirming the service is running, you can create a new repository either through the Gogs web interface (screenshots omitted) or via the command line. To create a repository from the command line, run:

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://192.168.20.40:3000/hahashen/devops.git
git push -u origin master

To push an existing local project, follow these steps:

mkdir -pv /soft/shell
cd /soft/shell
git init
vim hahage.sh   # add your files
git add *
git commit -m "hahashen"
git remote add origin http://192.168.20.40:3000/hahashen/devops.git
git push -u origin master

If you want to avoid entering a password each time, edit the repository’s .git/config file and embed the credentials in the URL, e.g.:

[remote "origin"]
    url = http://hahashen:[email protected]:3000/hahashen/devops.git

After updating the config, pushing again will not prompt for a password.

Cloning the repository without Jenkins can be done with:

git clone http://192.168.20.40:3000/hahashen/devops.git

Once cloned, you can inspect the files in the working directory.

The article concludes by inviting readers to continue with a Jenkins‑Git integration tutorial.

devopsLinuxsystemdGogsGit server
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.