DEV Community

Mumtaz Jahan
Mumtaz Jahan

Posted on

Git Commands Every DevOps Engineer Must Know

Git Commands Every DevOps Engineer Must Know

Git is not just a version control tool — it's your daily survival kit as a DevOps engineer. Whether you're managing pipelines, fixing production issues, or collaborating with teams, these commands will save you every single day.

Let's break it down section by section.


1. Initial Setup — Configure Git & Start Your Project

Before anything else, set up Git properly:

# Set your global username
git config --global user.name "Your Name"

# Set your global email
git config --global user.email "your@email.com"

# Initialize a new Git repository
git init

# Clone an existing repository
git clone <repo-url>
Enter fullscreen mode Exit fullscreen mode

Tip: Start every project the right way — proper config avoids identity issues in commits later.


2. Daily Git Flow — Your Everyday DevOps Cycle

This is the cycle you'll repeat every single day:

# Check the status of your changes
git status

# Stage all changes to be committed
git add .

# Commit your changes with a message
git commit -m "your message here"

# Push changes to remote repository
git push
Enter fullscreen mode Exit fullscreen mode

Tip: Practice it. Automate it. Master it.


3. Branching Strategy — Work Smarter in CI/CD & Teamwork

Branching is essential for clean CI/CD pipelines:

# List all branches in your repository
git branch

# Create a new branch and switch to it
git checkout -b feature-branch

# Switch to an existing branch
git switch branch-name

# Merge changes from another branch
git merge branch-name
Enter fullscreen mode Exit fullscreen mode

Tip: Always keep your main branch clean and stable. Never push untested code directly to main.


4. Sync With Remote — Keep Your Local Repo Up to Date

Always sync before you push:

# Fetch and merge changes from remote to local
git pull

# Fetch changes from remote (without merging)
git fetch

# Show remote repositories and their URLs
git remote -v
Enter fullscreen mode Exit fullscreen mode

Tip: Always git pull before you git push — it helps you avoid conflicts and ensures successful deployments.


5. Debug Like a Pro — Inspect History, Changes & Code

When something breaks in production, these are your best friends:

# Show commit history
git log

# View changes between working tree, staging or commits
git diff

# Show details of a specific commit
git show <commit-id>

# See who changed each line and why
git blame <file>
Enter fullscreen mode Exit fullscreen mode

Tip: git blame helps you find who broke production 👀 — use it wisely!


6. Undo & Fix — Life Saver Commands

Mistakes happen. Fix them like a pro:

# Undo last commit, keep changes staged
git reset --soft HEAD~1

# Undo last commit and discard all changes (Use with caution!)
git reset --hard HEAD~1

# Safely undo changes by creating a new commit (great for shared repos)
git revert <commit-id>

# Temporarily save changes and clean your working directory
git stash
Enter fullscreen mode Exit fullscreen mode

Tip: Use git revert over git reset --hard in shared/production repos — it's safer and keeps history clean.


7. Bonus — Extra Power Commands

Level up your Git game:

# Create a tag for a specific version
git tag -a v1.0 -m "version 1.0"

# Push a specific tag to remote
git push origin v1.0

# Apply a specific commit from another branch
git cherry-pick <commit-id>

# Check repository integrity and find issues
git fsck --full

# Remove untracked files and directories
git clean -fd
Enter fullscreen mode Exit fullscreen mode

Tip: Master these commands and you're ready to tackle any DevOps workflow with confidence!


Quick Reference Summary

Command What it does
git status Check current changes
git pull Sync from remote
git stash Save work temporarily
git revert Safely undo in shared repos
git blame Find who changed what
git cherry-pick Apply specific commits
git tag Version your releases

Final Thought

Git is the backbone of every DevOps workflow. The engineers who know these commands deeply don't just push code — they ship with confidence.

Save this post for your next deployment!


*Which Git command has saved you the most in production? Drop it in the comments *


Top comments (0)