Day 9 - Git Interview Questions, Answers & Commands (DevOps-Focused)
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Search for a command to run...
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
No comments yet. Be the first to comment.
1. Difference between Docker and Kubernetes Docker → Builds and runs containers.Kubernetes → Orchestrates containers across multiple nodes. Key points: Docker = container runtime. Kubernetes = container orchestration tool. Kubernetes provides auto...
In this session, we learn how to monitor a Kubernetes cluster using Prometheus and Grafana.This is not just theory — there is a GitHub repository containing all installation commands and demo steps.The repo will also be enhanced later with advanced K...
1. What is a ConfigMap in Kubernetes? A ConfigMap is used to store non-sensitive configuration data that your application needs — such as: Database port Connection type Any general configuration values In normal applications (non-Kubernetes), de...
Kubernetes normally supports built-in resources like: Deployment Service Pod ConfigMap Secret Ingress These are called native resources. Sometimes companies (Istio, ArgoCD, Prometheus Operator, Kyverno, etc.) want to add new features that Kub...
1. Why Kubernetes Services Are Needed When a Pod is created in Kubernetes, it receives a dynamic IP address.If the Pod dies and restarts, its IP changes.So other Pods (like checkout → payments) cannot rely on Pod IP because it changes, creating issue...
Below is the simplest and cleanest breakdown of all key Git concepts used daily by DevOps, SRE, and software engineers, including real-world examples, use-cases, and interview-ready answers.
Interview Answer:
Git is a distributed version control system (DVCS) used to track code changes, collaborate with teams, manage versions and branches, and ensure rollback capability.
Key Points:
Distributed → every developer has full repository copy
Supports branching, merging, rollback, auditing
Provides collaboration between developers + CI/CD pipelines
Command:
git init
What happens?
Creates a .git directory in the project folder
This folder stores:
commits
branches
logs
configuration
hooks (pre-commit, pre-push etc.)
Interview Answer example:
“When we run git init, Git creates a .git directory that stores all metadata needed for version control — such as commit history, branches, configuration, and hooks.”
Shows:
untracked files
modified files
staged files
current branch
Command:
git status
Using the git add command.
git add filename
git add . # add all files
Purpose:
Stages the changes so Git starts tracking them.
Interview Answer:
"git add moves changes to the staging area so Git knows which files should be included in the next commit."
Commit = snapshot + message
git commit -m "Added addition function"
Why required?
Provides history
Enables rollback
Helps to track “who changed what & why”
Crucial for CI/CD pipelines
Interview Answer:
“Commits help maintain proper version history. Each commit contains an author, timestamp, and commit message, making debugging and rollback easier.”
git log
git push
If remote not configured:
git remote add origin <repo-url>
git push -u origin main
Interview Answer:
"git clone is used to download or copy an existing remote repository into your local machine."
Command:
git clone <repo-url>
| Feature | Clone | Fork |
| Purpose | Download repo | Create independent copy on your account |
| Use case | Work on same project | Start your own version or contribute |
| Ownership | Not yours | Belongs to your GitHub account |
| Updates | Stays linked | Independent unless synced manually |
Interview Answer:
“Clone downloads a repo as-is, while fork creates an independent copy under your GitHub account — often used in open-source contributions.”
Uses username + password
Easy to start, but asks credentials repeatedly
Uses public/private keys
Best for DevOps teams
More secure
Generate SSH key:
ssh-keygen -t rsa
Copy public key:
cat ~/.ssh/id_rsa.pub
Add it to GitHub → Settings → SSH Keys
To avoid breaking the production code.
Real Example:
Amazon developers create a separate branch for “Carpenter Service Feature” instead of changing main directly.
git branch feature-division
git checkout -b division
git checkout main
These are important interview topics.
Used to combine two branches.
git checkout main
git merge division
Pros:
Safe
Maintains commit history
Best for team collaboration
Moves branch commits to top of another branch (linear history).
git checkout division
git rebase main
Pros:
Clean history
Cons:
Can cause conflicts
Don’t rebase shared branches
Pick specific commit(s) from another branch.
git cherry-pick <commit-id>
Use Case Example:
Production bug fix committed in feature branch → pick only that commit to main.
Shows changes line-by-line.
git diff
git checkout -- filename
git reset filename
git revert <commit-id>
git reset --hard <commit-id>
Used daily by DevOps.
Saves uncommitted work temporarily:
git stash
Restore:
git stash pop
Located in .git/hooks
Examples:
pre-commit → prevent secrets/credentials from being committed
pre-push → run tests before pushing
post-merge → notify CI/CD
git pull
git checkout -b feature-x
git add .
git commit -m "Added feature"
git push
Create Pull Request → Merge to main