Console9

How to track server configs with Git

Version-control server configuration files under /etc using Git for change tracking and rollback.

How to track server configs with Git

Version-control server configuration files under /etc using Git for change tracking and rollback.

Prerequisites

  • Git and root access on a Linux server.

Step-by-Step: Track Server Configs with Git

  1. Initialize a Git repository in /etc:

    cd /etc
    sudo git init
  2. Create a .gitignore to exclude volatile files:

    sudo tee /etc/.gitignore << 'EOF'
    mtab
    adjtime
    ld.so.cache
    resolv.conf
    *.cache
    *.pid
    EOF
  3. Add and commit the initial configuration state:

    sudo git add -A
    sudo git commit -m "Initial commit of /etc configuration"
  4. After making configuration changes, commit them with a descriptive message:

    sudo git add -A
    sudo git commit -m "Increase Nginx worker_connections to 4096"
  5. View the change history:

    sudo git log --oneline
  6. Roll back a change by reverting a specific commit:

    sudo git revert abc1234