Free tech learning for everyone, from basics to pro

ScriptingProgramming and Application SecurityBeginner

Git basics for engineers: commits, branches and remotes

In short: Git records every change to your scripts and configs, who made it and why. You stage and commit changes locally, use branches to work safely, and push to a shared remote where colleagues review and merge them.

Why engineers need version control

Without version control, scripts live in folders called final, final2 and final-really. Git is a distributed version control system: it keeps a full history of every change, lets several people work at once and makes it easy to undo mistakes. Network teams use it for scripts, Ansible playbooks, templates and even device configuration backups.

Where your changes liveWorking treefiles you editStaging areagit addLocal repogit commitRemotegit push
Figure 1. Changes move from your files to the staging area, into local history, then out to a shared remote.

The everyday commands

git config --global user.name  "Your Name"
git config --global user.email "you@example.com"

git init netops-scripts && cd netops-scripts
git status                       # what changed?
git add check_hosts.sh           # stage a file
git commit -m "Add host reachability check"
git log --oneline --graph        # short history
git diff                         # unstaged changes
git restore check_hosts.sh       # throw away unstaged edits

A commit is a snapshot with a message. Good messages are short and say why: "Increase ping timeout for satellite sites" is far more useful than "update". Commit small, related changes together so each one is easy to review and, if necessary, revert.

Branches and merging

Feature branch workflowBranchgit switch -cCommitsmall stepsPushto remoteReviewpull requestMergeinto mainUpdategit pull
Figure 2. A simple team workflow: work on a branch, push it, review it, merge it and pull the latest main.

A branch is a movable label for a line of work. You create a branch for each change, so the main branch always holds tested, working code.

git switch -c fix/ping-timeout   # create and move to a new branch
# ...edit, add, commit...
git switch main
git merge fix/ping-timeout
git branch -d fix/ping-timeout

If two branches change the same lines, Git reports a merge conflict and marks the file. You edit the file to keep the right version, then git add and git commit to finish.

Remotes and collaboration

A remote is a copy of the repository on a server such as GitHub, GitLab, Bitbucket or an internal Gitea instance.

git clone git@git.example.com:netops/scripts.git
git pull                          # fetch and merge others' work
git push -u origin fix/ping-timeout

On the hosting platform you open a pull request (GitLab calls it a merge request). A colleague reviews the change, automated checks such as linters run, and then it is merged. This is the same peer review you would want for any production change.

MistakePrevention
Committing passwords or API keysKeep secrets in a vault or environment variables, add secret files to .gitignore, enable secret scanning
Working directly on mainProtect the main branch and require pull requests
Huge commits mixing many changesCommit one logical change at a time
Force-pushing shared branchesAvoid git push --force except on your own branches

A secret pushed to a remote should be treated as exposed: rotate it straight away, because removing it from history does not undo copies others may have pulled.

Tip: a public Git repository of your lab scripts and playbooks makes a strong portfolio when you apply for network automation roles.

Practice

What is the difference between git add and git commit?
git add stages changes for the next snapshot; git commit records the staged snapshot in the local history with a message.
Why work on a branch instead of main?
It keeps main stable and lets the change be reviewed and tested before it is merged.
You pushed an API key by mistake. What is the first thing to do?
Revoke or rotate the key immediately, then clean the history and add protections such as .gitignore and secret scanning.

Key takeaways

  • Git tracks every change, who made it and why.
  • Files move from working tree to staging to commits to the remote.
  • Use a branch per change and merge through reviewed pull requests.
  • Write small commits with messages that explain why.
  • Never commit secrets; rotate any that leak.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
FM TecHub Team
Role
Editorial team
Reviewer credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

The team writes practical, plain-English guides on networking, security and cloud.

More about the team →

Original content written by the FM TecHub Team. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Get free updates by email

New notes, tools, CCNA and Security+ tips and important security news from FM TecHub, explained simply. Free, about twice a month. Unsubscribe anytime; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesup

Free · no spam · past emails · powered by Buttondown