Tutorials · DevOps & Containers

How to Keep Network Configurations in Git (Configuration as Code)

Store every switch, gateway and edge-server configuration in Git: you get history, diffs, reviews and a fast way back to the last working version.

Intermediate12 min5 steps

Before you start

  • Git and a private repository (self-hosted or cloud)
  • Read access to device configurations over SSH or the API

Step by step

  1. Create the repository layout

    One folder per site, one file per device, plus compose files and docs.

    network-config/
      site1/
        core-sw.cfg
        gateway.cfg
        edge/compose.yaml
      site2/
      README.md
    
  2. Collect configurations automatically

    Pull running configurations nightly with a script or a tool such as Oxidized, and commit only when something changed.

    cd network-config && git add -A
    git diff --cached --quiet || git commit -m "nightly backup $(date +%F)"
    
  3. Review changes

    Make planned changes on a branch, review the diff with a colleague, then merge and apply.

  4. See what changed

    When something breaks, the diff shows exactly what was changed and when.

    git log --oneline -- site1/core-sw.cfg
    git diff HEAD~1 -- site1/core-sw.cfg
    
  5. Protect secrets

    Strip or encrypt passwords and keys before committing (for example with git-crypt or SOPS), and limit who can read the repository.

Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.

Pro tips

  • Tag the repository before every maintenance window.
  • Keep a copy of the repository off-site with your other backups.