Console9

Git tutorial: version control for sysadmins

Learn Git fundamentals by version-controlling Nginx configuration files — init, commit, branch, and push.

Git tutorial: version control for sysadmins

Learn Git fundamentals by version-controlling Nginx configuration files — init, commit, branch, and push.

What You Will Need

  • Git installed on a Linux server.
  • Root or sudo access.

Step 1: Initialize a Git Repository for Nginx Configuration

Git creates a new repository in the current directory. Initialize one inside the Nginx configuration directory:

cd /etc/nginx
sudo git init
sudo git add .
sudo git commit -m "Initial commit of Nginx configuration"

Git now tracks every file in /etc/nginx. Any future change can be reviewed, compared, and reverted.

Step 2: Make and Commit a Configuration Change with Git

Edit a configuration file and record the change as a Git commit:

sudo nano /etc/nginx/nginx.conf
# Change worker_connections to 4096
sudo git add nginx.conf
sudo git commit -m "Increase worker_connections to 4096"

Each commit stores who made the change, when, and a message describing why. Use git log to review history.

Step 3: Create a Branch for Testing Changes with Git

Git branches allow testing changes without affecting the working configuration. Create a branch for an experimental SSL setup:

sudo git checkout -b ssl-experiment

Make changes on this branch. If the experiment fails, switch back to the main branch — the original configuration is intact:

sudo git checkout main

If the experiment succeeds, merge it:

sudo git merge ssl-experiment

Step 4: Push the Repository to a Remote for Backup with Git

Create a bare repository on a backup server and push:

# On the backup server:
git init --bare /srv/git/nginx-config.git

# On the Nginx server:
sudo git remote add origin user@backup:/srv/git/nginx-config.git
sudo git push -u origin main

What You Learned

This tutorial covered Git initialization ( git init), staging and committing changes ( git add, git commit), viewing history ( git log), branching for safe experimentation ( git checkout -b), merging ( git merge), and remote backup ( git remote add, git push). These operations form a complete version control workflow for server configuration management.