Mental model
If you have ever named a file config-v2-FINAL-reallyfinal.txt, you have reinvented version control the bad way. Git is the good way.
Think of Git as a save point system for files, like a video game. Each save point is a commit. You can go back to any save point, see what changed since the last one, and work on parallel versions of the same files without them ever stepping on each other.
For network automation this matters because:
- Your scripts, playbooks and configs are just files.
- A broken playbook that worked yesterday has a bug introduced between then and now. Git tells you exactly what changed.
- You can try an experiment on a branch, throw it away if it fails, and nothing else is touched.
- Pushing to GitHub means your laptop dying does not lose your work.
You do not need to know software engineering workflows. You need init, add, commit, log, push, pull, and a mental model of branches. That is the entire exam relevant surface for CCNA Automation (200-901).
The four commands you use every day
| Command | What it does | When |
|---|---|---|
git init | Make this folder a Git repository | Once, when you start a new project |
git add <file> | Mark a file to go into the next save point | Every time you edit something you want to keep |
git commit -m "<message>" | Make a save point with a short message | After git add, when you are happy with the change |
git log | List every save point so far | Any time you want to see history |
Two more for working with GitHub (covered below):
git push: upload your local commits to GitHub.git pull: download other people’s commits from GitHub.
That is enough. Everything else (merge, rebase, cherry pick) is a sharper tool for the same job: moving commits around.
Run your first Git workflow in your browser
13 scripted steps in a real terminal. Type each command, press Enter, see the real output. Hint and Show the answer on every step. Reset to start over.
Zero install. No network needed. No GitHub account.
Open the lab →Branches: parallel universes
A branch is a separate line of save points. The default branch is called main. If you want to try something risky, make a branch:
git checkout -b try-netmiko
Any commit you make now goes onto try-netmiko, not main. If the experiment works, you merge back:
git checkout main
git merge try-netmiko
If it fails, you throw the branch away and nothing on main was ever touched:
git checkout main
git branch -D try-netmiko
That is a big deal for network automation: rewrite a playbook on a branch, break it in interesting ways, and never worry you have corrupted what everyone else is using.
Pushing to GitHub
To share your repository, create an empty one on GitHub, then connect your local one:
git remote add origin https://github.com/you/net-scripts.git
git push -u origin main
After that first push, git push on its own sends new commits up, and git pull brings down anything others pushed.
The #1 mistake
Committing a password, SSH key or API token to a public repository. Once pushed, it is in Git history forever, and crawlers find it in minutes. Everyone has done this at least once.
Prevention:
- Put secrets in a
.envfile. Add.envto.gitignore. Thengit statuswill not even show the file. - If you have already pushed a secret, rotate the credential right now (change the password, revoke the token) and only then clean the Git history. Removing a secret from Git does not un-publish it.
FAQ
Do I need GitHub to use Git? No. Git works entirely offline. GitHub is a cloud service that hosts Git repositories so other people can see and contribute. The lab linked above uses zero cloud services.
Why is my first commit called “root commit”? Git prints (root-commit) on the first commit of a repository because it has no parent commit. Every commit after that has at least one parent.
What does --oneline do on git log? Shows one short line per commit instead of the full multi line default. Useful when the history is long.
Which editor opens when I run git commit without -m? Whatever $EDITOR points to. On Linux that is often vim. If vim surprises you, type :q! and press Enter to exit, then run git commit -m "your message" to skip the editor entirely.
Can I use Git for Cisco configs, not just scripts? Yes. Many teams keep a Git repository of running configs backed up from every switch and router. Any change becomes a commit, so you have a full change history across the network.
