Git for Network
Git for Network
ENGINEER
GIT BASICS
STRUCTURE
GIT
1
INTRODUCTION - WHAT IS GIT?
In today’s networked world, version control isn’t just for developers. With infrastructure-as-code,
automation, and programmable networks, Git has become essential for network engineers. This
guide explores how Git can transform your workflow, prevent misconfigurations, and enhance
collaboration.
https://git-scm.com/ Or install
via terminal:
cd net-automation
git init
touch readme.md
cd network-scripts
git diff
Once tested:
git status
git diff
git add .
git commit
git stash
# Later
git log
# Script:
git push
INTEGRATING GIT WITH ANSIBLE & NETMIKO
Store Ansible playbooks in Git.
Store Netmiko Python scripts with version tracking.
Share credentials and inventory templates securely.
COLLABORATING AS A TEAM
Use Pull Requests to review code/configs.
Assign reviewers and approve changes.
Track issues or feature requests using GitHub Issues.
*.log
*.pem
passwords.yaml
# Device details
device = {
"device_type": "cisco_ios",
"host": "192.168.1.10",
"username": "admin",
"password": "cisco123",
# VLAN configuration
vlan_id = "50"
vlan_name = "Mgmt_VLAN"
commands = [
f"vlan {vlan_id}",
f"name {vlan_name}",
"exit"
try:
net_connect = ConnectHandler(**device)
output = net_connect.send_config_set(commands)
print(output)
net_connect.disconnect()
except Exception as e:
print(f"Error: {e}")
GIT REPOSITORY STRUCTURE EXAMPLE
network-configs-git/
├── README.md
├── .gitignore
├── scripts/
│ └── vlan_config_netmiko.py
├── configs/
│ └── switch01_backup_2024-05-04.cfg
├── docs/
│ └── vlan_strategy.md
└── logs/
└── vlan_config_log.txt
GIT WORKFLOW EXAMPLE
1. Clone your repo (first time):
cd network-configs-git
cp ~/Downloads/vlan_config_netmiko.py scripts/
5. Push to GitHub:
Version Control: Track changes, revert to stable states, and audit history with precision.
Collaboration: Work with your team on automation scripts, playbooks, and policies
seamlessly.
Automation Integration: Combine Git with tools like Netmiko, Ansible, and CI/CD for
consistent deployments.
Disaster Recovery: Swiftly recover from outages by restoring known-good configurations
from Git history.
No matter your current skill level, starting small—by versioning backup configs or storing Netmiko
scripts—is a meaningful first step. Over time, Git will become the backbone of your NetDevOps
journey.