Skip to main content
PacketMentor logo
Open menu
← All topics
Automation & Programmability Foundational

Git Basics for Network Engineers

The four Git commands network engineers use every day: init, add, commit, log. Pairs with a dedicated in-browser lab you can run in five minutes, no install needed.

Quick summary
  • Git is a save point system for files. A 'commit' is a save point. A 'branch' is a parallel universe. 'push' uploads your work to GitHub.
  • Four commands cover 90 percent of day to day work: init, add, commit, log. Add push and pull once you connect to GitHub.
  • Hands-on lab is on its own page: /automation-labs/git-basics/ (13 steps, 5 minutes, zero install).

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

CommandWhat it doesWhen
git initMake this folder a Git repositoryOnce, when you start a new project
git add <file>Mark a file to go into the next save pointEvery time you edit something you want to keep
git commit -m "<message>"Make a save point with a short messageAfter git add, when you are happy with the change
git logList every save point so farAny 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.

Hands-on lab · 5 minute walkthrough

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 →
git-basics · lab
you@laptop:~$ git init
Initialized empty Git repository in /home/you/net-scripts/.git/
you@laptop:~/net-scripts$ git commit -m "add first command list"
[main (root-commit) f3d8c21] add first command list 1 file changed, 1 insertion(+)
you@laptop:~/net-scripts$ git log --oneline
a71b4d9 add interface check
f3d8c21 add first command list
you@laptop:~/net-scripts$

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 .env file. Add .env to .gitignore. Then git status will 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.

Master this on a real network

Want this drilled into reflex?

1:1 weekly sessions, live feedback on your labs, and US interview prep: built around the CCNA Automation® exam blueprint. Free first session. No card on file until you decide.

Claim my free session →

Get the free CCNA 12-week roadmap

You're already reading up on Git Basics for Network Engineers. The roadmap is the order I recommend studying every CCNA topic in: with what to lab each week and where Git Basics for Network Engineers fits. A written personal reply, not an autoresponder. Expect it within one business day.

Personal reply from a senior network engineer. No third-party tracking. Unsubscribe any time.