ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

Keeping configuration in Git

Lesson 10.18 minAdvancedDecember 1, 2026
Open

This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.

Key points

  • Git stores every change as a commit: who changed what, when and why.
  • The main cycle: git status → git add file → git commit -m "what and why" → git log.
  • git diff shows changes not yet committed, git log -p file a file's history; git restore file discards a change.
  • Remote repo: git clone, git pull, git push; a branch lets you try a change without touching the main version.
  • Never commit secrets (passwords, keys); a .gitignore file keeps them out.

Why Git for an admin

Without GitWith Git
httpd.conf.bak, httpd.conf.bak2, httpd.conf.kohneOne file, all versions in the history
"Who changed it?" — stays a questiongit log — author, date, reason
Reverting a bad setting — relying on memorygit revert or git restore
Moving settings to another server — by handgit clone

This approach is called Infrastructure as Code: the state of servers is described in files, and those files are kept in Git. Ansible in the next two lessons builds on this idea.

Getting started

srv-web01
[ali@srv-web01 ~]$ sudo dnf install -y git
[ali@srv-web01 ~]$ git config --global user.name "Ali"
[ali@srv-web01 ~]$ git config --global user.email "[email protected]"
[ali@srv-web01 ~]$ mkdir -p ~/infra && cd ~/infra
[ali@srv-web01 infra]$ git init
Initialized empty Git repository in /home/ali/infra/.git/

user.name and user.email are written into every commit — they show who made the change.

The main cycle

srv-web01
[ali@srv-web01 infra]$ mkdir -p httpd && cp /etc/httpd/conf.d/shop.conf httpd/
[ali@srv-web01 infra]$ cp ~/bin/*.sh . 
[ali@srv-web01 infra]$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	disk-xeberdar.sh
	httpd/
	port-yoxla.sh
[ali@srv-web01 infra]$ git add .
[ali@srv-web01 infra]$ git commit -m "İlk versiya: shop vhost və yoxlama skriptləri"
[main (root-commit) 3e1a9c2] İlk versiya: shop vhost və yoxlama skriptləri
 3 files changed, 41 insertions(+)
StateMeaningCommand
UntrackedGit does not track the filegit add
ModifiedChanged but not stagedgit add
StagedReady for the next commitgit commit
CommittedIn the history—

Following a change

srv-web01
[ali@srv-web01 infra]$ sed -i 's/ErrorLog .*/ErrorLog \/var\/log\/httpd\/shop-err.log/' httpd/shop.conf
[ali@srv-web01 infra]$ git diff
diff --git a/httpd/shop.conf b/httpd/shop.conf
--- a/httpd/shop.conf
+++ b/httpd/shop.conf
@@ -5,6 +5,6 @@
     <Directory /srv/shop>
         Require all granted
     </Directory>
-    ErrorLog /var/log/httpd/shop-error.log
+    ErrorLog /var/log/httpd/shop-err.log
     CustomLog /var/log/httpd/shop-access.log combined
[ali@srv-web01 infra]$ git commit -am "shop: error log adı qısaldıldı"
[ali@srv-web01 infra]$ git log --oneline
7b2d4f1 (HEAD -> main) shop: error log adı qısaldıldı
3e1a9c2 İlk versiya: shop vhost və yoxlama skriptləri

- is the old line, + the new line. git commit -am commits already tracked files without add.

A good commit message says what changed and why: "nginx: worker count raised to 4 — the CPU has 4 cores". Messages like "fix" or "test" say nothing a month later.

CommandWhat it does
git log --onelineA short history
git log -p fileAll changes to a file
git show 7b2d4f1The contents of one commit
git blame fileWho wrote each line, in which commit
git restore fileDiscard an uncommitted change
git revert 7b2d4f1A new commit that undoes a commit (the history stays)

Keeping secrets out

srv-web01
[ali@srv-web01 infra]$ cat > .gitignore <<'EOF'
*.key
*.pem
.smbcred
secrets/
EOF
[ali@srv-web01 infra]$ git add .gitignore && git commit -m ".gitignore: açarlar və sirlər"

Once a password, private key or token is committed, deleting the file is not enough — it stays in the history. In that case change the secret immediately. Ansible has ansible-vault for secrets (next lesson).

Remote repos and branches

For team work, a central repo (GitLab, Gitea, GitHub, or just a server reachable over SSH):

srv-web01
[ali@srv-web01 infra]$ git remote add origin ali@srv-db01:/srv/git/infra.git
[ali@srv-web01 infra]$ git push -u origin main
[ali@srv-web01 infra]$ git switch -c test-yeni-port
[ali@srv-web01 infra]$ git commit -am "shop: 8090 portunda sınaq"
[ali@srv-web01 infra]$ git switch main
[ali@srv-web01 infra]$ git merge test-yeni-port
CommandWhat it does
git clone URLTake a copy of a repo
git pullBring in remote changes
git pushSend your commits
git switch -c nameCreate a new branch and switch to it
git merge nameMerge the branch into the current one

A branch is for trying a change without touching the main version. In a team, a change is usually prepared on a branch and accepted into the main branch after review through a pull request (merge request).

For /etc: etckeeper

To keep all of /etc in Git automatically, there is the etckeeper package from EPEL: it commits after every dnf transaction and daily. This fully answers "who changed what in /etc".

Lab: an infra repo

On your own VM (or with configuration files in the simulator):

  1. Install git, set user.name and user.email.
  2. Create the ~/infra repo, add one configuration file and one script, and make the first commit.
  3. Change a line in the configuration file, look at it with git diff, and commit with a meaningful message.
  4. Look at the history with git log --oneline and git log -p.
  5. Create .gitignore and check that a test.key file does not appear in git status.
srv-web01
[ali@srv-web01 infra]$ touch test.key
[ali@srv-web01 infra]$ git status --short
[ali@srv-web01 infra]$ git log --oneline | head -n 3

Check: there are at least three commits; test.key does not appear in git status.

Check yourself

5 questions · answers are shown instantly · 3 correct answers complete the lesson

1Which command stages a change for the next commit?

Then git commit.

2Which command shows changes not yet committed?

- old line, + new line.

3How do you undo a bad commit without erasing the history?

revert creates a new, opposite commit.

4A password was committed by accident. What is the most important step?

Anyone with a copy of the history can see the old password.

5Which command shows who wrote each line of a file?

Line, commit and author.
Was this lesson useful?

Comments

Sign in to comment.