Git Commands Cheat Sheet: Essential Commands for Network & DevOps Engineers

Git Commands Cheat Sheet: Essential Commands for Network & DevOps Engineers

Whether you're managing config templates, automating infrastructure, or versioning playbooks, Git is your best friend. Here’s a quick-reference guide to the most useful Git commands, categorized by use case.

🔧 Setup & Configuration

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

Set your identity for all Git operations.

git config --list

Check your Git configuration.

📦 Creating & Cloning Repositories

git init

Initialize a new Git repo (e.g. for Ansible playbooks or Jinja2 templates).

git clone <repo-url>

Clone an existing repo (ideal for pulling network automation scripts).

📄 Working with Files

git status

Check which files have been modified or staged.

git add <filename>      # or use . to add all changes

Stage files for commit.

git commit -m "Your message"

Save your changes with a description.

git rm <filename>

Remove a file and stage the deletion.

🕹 Branching & Merging

git branch

List all branches.

git branch <name>

Create a new branch (e.g. feature/pfc-tcam-tuning).

git checkout <branch>

Switch to a branch.

git merge <branch>

Merge another branch into your current one.

⬆️ Push & Pull Changes

git push origin <branch>

Upload local changes to the remote repo.

git pull origin <branch>

Fetch and merge changes from the remote.

git fetch

Download changes from remote but don’t merge.

🕰 Revert & Reset

git log

View commit history.

git diff

See unstaged changes.

git checkout -- <file>

Discard local changes to a file.

git reset HEAD <file>

Unstage a file (keeps changes, just removes from staging area).

git revert <commit>

Undo a specific commit by creating a new one.

🧪 Bonus: Tagging for Releases

git tag v1.0

Create a simple tag (great for config versioning).

git push origin --tags

Push tags to the remote repo.

💬 Final Tip

Use .gitignore to avoid committing compiled files, device secrets, or debug logs:

echo "*.log" >> .gitignore
echo "secrets.yml" >> .gitignore

Subscribe to LevelUp I.T. newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!