Git Basics For Fresher DevOps

Git Basics Every DevOps Fresher Should Know π
As a DevOps fresher, Git is one of the most important tools you must learn. In this short blog, Iβll share basic Git commands that helped me a lot.
πΉ What is Git?
Git is a distributed version control system used to track code changes.
πΉ Most Used Git Commands
git initβ Initialize a repositorygit statusβ Check file statusgit add .β Stage changesgit commit -m "message"β Save changesgit pushβ Push code to GitHub
πΉ Why Git is Important for DevOps?
Helps manage infrastructure code
Supports CI/CD pipelines
Enables team collaboration
π€ Advanced Mock Interview β Git & GitHub for DevOps (Senior Level)
Scenario 1 β Secret leaked AND forked
Interviewer:
A developer pushed a secret to GitHub. Before you noticed, someone forked the repo. What now?
You:
Rotate the secret immediately, invalidate the compromised credentials, then remove the secret from history. After that, treat the secret as fully compromised and monitor for abuse.
Explanation:
Forks copy history. You cannot guarantee deletion everywhere. Rotation is the only safe action.
Example:
git filter-repo --path .env --invert-paths
git push --force
aws iam delete-access-key
aws iam create-access-key
Scenario 2 β CI pipeline compromised
Interviewer:
Someone modified .github/workflows/deploy.yml to echo secrets into logs. What do you do?
You:
Disable pipeline, rotate all exposed secrets, audit logs, revert malicious commit, lock down workflow permissions.
Explanation:
CI has production access. Treat it as a security incident.
Scenario 3 β Git history rewritten in main
Interviewer:
Someone ran git push --force on main. Production is now inconsistent.
You:
Stop deployments, restore main from last known good commit or tag, communicate with team, enforce branch protection.
Scenario 4 β Partial deployment failure
Interviewer:
Your pipeline deploys to 5 regions. One region failed mid-deploy.
You:
Detect drift, rollback failed region or roll forward consistently.
Explanation:
Inconsistent versions cause data corruption.
Scenario 5 β GitOps controller outage
Interviewer:
ArgoCD is down and cannot sync infra. A critical change is needed.
You:
Apply emergency change manually, document it, reconcile back into Git once GitOps is restored.
Scenario 6 β Malicious PR with hidden intent
Interviewer:
A PR passes CI but secretly opens a backdoor in code.
You:
Use code review, static analysis, runtime security, principle of least privilege.
Scenario 7 β Repo with 2k commits slow
Interviewer:
Large monorepo is slow to clone.
You:
Use shallow clones, partial checkouts, split repo or use sparse checkout.
Scenario 8 β Accidental deletion of main
Interviewer:
Someone deleted the main branch.
You:
Restore from remote or GitHub UI, recreate protection.
Scenario 9 β Audit after breach
Interviewer:
Security asks: βWhich secrets were exposed in last 90 days?β
You:
Scan git history, logs, PRs, rotate all suspicious credentials.
Scenario 10 β GitHub outage during incident
Interviewer:
GitHub and registry are down; production is failing.
You:
Use last built artifact, emergency manual deploy, post-incident sync.
π§ Deep Explanation Patterns
| Concept | Why Important |
| History rewrite | Can destroy audit trail |
| Secrets in Git | Permanent exposure risk |
| Branch protection | Prevents human error |
| GitOps | Prevents drift |
| CI security | CI has prod access |
| Auditability | Compliance requirement |
π₯ Key Interview Phrases
Use these:
βI treat this as a security incident.β
βFirst I contain the blast radius.β
βWe restore service before root cause.β
βWe prevent recurrence using automation.β
π’ Final Tip
At senior level:
You are judged not on commands, but on:
Risk management
Blast radius control
Compliance & auditability
Team safety