Infrastructure as Code (IaC)
For a long time, system administration involved SSHing into a server and manually editing configuration files. If a mistake was made, you had to rely on your memory or a disorganized folder of `.bak` files to revert the changes. This ad-hoc approach is fundamentally incompatible with modern scale.
Today, infrastructure is treated exactly like software code. Configuration files (like Ansible playbooks, Terraform manifests, and Nginx configurations) are stored, tracked, and collaborated on using Version Control Systems (VCS). Git is the undisputed industry standard for version control. This guide will introduce you to the core concepts of Git from a sysadmin's perspective.
Core Concepts of Git
Unlike centralized version control systems (like SVN), Git is distributed. Every developer (or sysadmin) has a complete, local copy of the entire history of the project.
1. The Repository (Repo)
A repository is simply a folder that Git is tracking. When you initialize a repository, Git creates a hidden .git folder where it stores all the tracking metadata and history.
2. The Staging Area
When you edit a file, Git notices the change, but it doesn't automatically save it to the history. You must explicitly tell Git to track the specific changes you just made. Moving a changed file to the "Staging Area" tells Git: "I want this specific modification to be included in my next save point."
3. The Commit
A commit is a permanent snapshot of your staged files at a specific point in time. Every commit requires a "commit message" explaining why the change was made.
Basic Git Workflow
Let's walk through the day-to-day workflow of modifying an Nginx configuration file tracked by Git.
Step 1: Initialize or Clone
If you are starting a new project, you initialize a repo. If you are joining an existing project, you clone it from a remote server (like GitHub or GitLab).
git init # OR
git clone https://github.com/my-org/nginx-configs.git
Step 2: Check Status
Before doing anything, it is a good habit to check the current state of your repository.
git status
Step 3: Stage Changes
After editing nginx.conf, use the add command to stage the file.
git add nginx.conf
Step 4: Commit
Create a snapshot of the staged changes with a descriptive message.
git commit -m "Increased worker_connections to 2048 to handle traffic spike"
Step 5: Push to Remote
Finally, upload your local commit to the central remote server so your team can see it and CI/CD pipelines can deploy it.
git push origin main
Branching and Safe Testing
The true power of Git lies in branching. A branch is an independent line of development. As a sysadmin, you should never make changes directly to the main branch.
Instead, create a new branch (e.g., test-new-firewall-rules), make your changes, and test them. If they fail, you simply delete the branch, and the main configuration remains untouched. If they succeed, you "merge" the branch back into main.
Conclusion
Git is no longer just a tool for software developers. For system administrators, it provides an infallible audit trail (who changed what, when, and why), enables seamless collaboration, and forms the bedrock of automated CI/CD deployment pipelines. Embracing Git is the first step toward mastering Infrastructure as Code.