Chapter 70: DevOps Interview Questions by Topic and Company
70.2 Git Interview Questions for DevOps Engineers
Git roj vaparto, pan interview madhe merge vs rebase vicharla ki gadbad hote. Aaj te clear karu.
What you will learn in this lesson
- 25 real Git questions with short answers
- Which companies asked them, from public interview stories
- Fresher, experienced and senior levels
- A simple way to answer: why, what, how
Why: the problem
Every team uses Git many times a day. Interviewers check if you can merge, fix conflicts and undo mistakes without breaking main.
What: how to read this lesson
Each question has a short answer in three parts.
- Why: the reason the thing exists.
- What: the plain meaning.
- How: how you use it, often with a small command.
"Asked at" names a company only when a public interview story says the question was asked there. No tag means it is a common question that many companies ask.
Companies with the most questions in this lesson: Wipro (6), Tech Mahindra (5), Deloitte (3), Infosys (2), Barclays (2), TCS (1).
How: answer any question in 4 steps
- Start with the reason. One sentence.
- Give the plain meaning. No big words.
- Show one command or file.
- Add one example from your work. Then stop and wait.
Fresher questions
Q1. What is the difference between git merge and git rebase?
Why: Teams pick one style for clean history.
What: Merge joins two branches with a merge commit and keeps history as it happened. Rebase replays your commits on top of the other branch, giving a straight line.
How: Rebase only your own local branch; never rebase shared, pushed branches.
git checkout feature && git rebase main
git checkout main && git merge feature
Q2. What is the difference between git pull, git fetch and git clone?
Why: Freshers mix these up.
What: clone copies a repo for the first time. fetch downloads new commits but does not change your files. pull = fetch + merge (or rebase).
How: Use fetch to look first, pull when ready.
git clone URL
git fetch origin
git pull --rebase origin main
Q3. What is git stash?
Why: You often need to switch branches with half-done work.
What: stash saves uncommitted changes aside and cleans the working folder.
How: Use stash, switch, then stash pop to bring changes back.
git stash push -m "wip login"
git stash list
git stash pop
Q4. What is .gitignore?
Why: Build files and secrets must not be committed.
What: .gitignore lists file patterns Git should not track.
How: Add it at repo root. Already tracked files need git rm --cached.
node_modules/
*.log
.env
Q5. How do you resolve a merge conflict?
Why: Conflicts happen in every team.
What: Git stops when two branches change the same lines.
How: 1) Open the file and find <<<<<<< markers. 2) Keep the right code. 3) git add. 4) git commit (or rebase --continue). Talk to the other developer if unsure.
git status
git add app.py
git commit
Q6. What are Git tags and why use them?
Why: Releases need a fixed name.
What: A tag is a name for one commit, like v1.2.0. Annotated tags store a message and author.
How: Create, push, and use tags to trigger release pipelines.
git tag -a v1.2.0 -m "release 1.2.0"
git push origin v1.2.0
Q7. How do you compare two branches?
Why: Before a merge you want to see what changes.
What: git diff and git log can compare branches.
How: Use diff for code, log for commits.
git diff main..feature
git log --oneline main..feature
Q8. What is the difference between git reset and git revert?
Why: One rewrites history, one does not.
What: reset moves the branch pointer back (local cleanup). revert adds a new commit that undoes an old one (safe for shared branches).
How: Use revert on main; use reset only on local, unpushed work.
git reset --soft HEAD~1
git revert HEAD
Q9. What is the difference between git reset --soft, --mixed and --hard?
Why: --hard can lose work.
What: --soft keeps changes staged. --mixed (default) keeps changes unstaged. --hard deletes changes.
How: Use --hard only when you are sure.
git reset --mixed HEAD~1
Q10. What is a pull request?
Why: It is how teams review code.
What: A PR asks to merge one branch into another, with review, comments and CI checks.
How: Keep PRs small, add a clear description, and require approvals and passing checks.
Q11. What is the difference between Git and GitHub?
Why: Basic, but very common.
What: Git is the version control tool on your machine. GitHub is a website that hosts Git repos and adds PRs, issues and Actions.
How: GitLab and Bitbucket are similar hosts.
Q12. What is the staging area in Git?
Why: It explains why git add exists.
What: The staging area (index) holds changes you plan to commit next.
How: You can stage only some files, or some lines with git add -p.
git add -p
git diff --staged
Q13. What is git log --oneline --graph used for?
Why: You need to read history quickly.
What: It shows commits one per line with branch lines.
How: Add --all to see every branch.
git log --oneline --graph --all
Q14. What is the difference between git commit --amend and a new commit?
Why: It keeps history tidy.
What: --amend replaces the last commit (message or files).
How: Do not amend commits already pushed to a shared branch.
git commit --amend -m "fix: correct port"
Experienced questions (2-5 years)
Q15. What is git cherry-pick?
Why: Hotfixes often need one commit on another branch.
What: cherry-pick copies one commit onto your current branch.
How: Find the commit ID with git log and pick it.
git checkout release/1.4
git cherry-pick a1b2c3d
Q16. How do you squash commits?
Why: Clean history makes reviews and reverts easy.
What: Squash joins many small commits into one.
How: Use interactive rebase and mark commits with s, or use "Squash and merge" in the PR.
git rebase -i HEAD~4
Q17. How do you recover a deleted branch?
Why: Mistakes happen; Git rarely loses work.
What: The branch's last commit is still in the reflog.
How: Find the commit in git reflog and create the branch again.
git reflog | grep feature-x
git checkout -b feature-x 9f8e7d6
Q18. How do you revert a merge commit?
Why: A bad merge on main must be undone safely.
What: git revert makes a new commit that undoes changes without rewriting history.
How: For a merge, tell Git which parent to keep with -m 1.
git revert -m 1 <merge-commit-id>
git push
Q19. Which branching strategy have you used?
Why: Strategy affects release speed.
What: Common ones: GitFlow (develop, release, hotfix branches), GitHub Flow (main + short feature branches), trunk-based (tiny branches, feature flags).
How: Say what you used, why, and how releases and hotfixes worked.
Q20. How do you handle a hotfix in production?
Why: Prod bugs need a fast, safe path.
What: A hotfix branch starts from the released code, not from develop.
How: 1) Branch from main/tag. 2) Fix and test. 3) Merge to main, tag, deploy. 4) Merge back to develop.
git checkout -b hotfix/1.4.1 v1.4.0
Q21. What is git bisect?
Why: It finds which commit broke something.
What: bisect does a binary search through history.
How: Mark a good and a bad commit; test each step Git gives you.
git bisect start
git bisect bad
git bisect good v1.0
Q22. What is a detached HEAD?
Why: Freshers panic when they see it.
What: HEAD points to a commit directly, not to a branch.
How: Fine for looking around; to keep work, create a branch.
git switch -c fix-from-here
Q23. How do you remove a secret that was committed by mistake?
Why: Leaked keys get abused within minutes.
What: Deleting the file in a new commit is not enough; it is still in history.
How: 1) Revoke/rotate the key first. 2) Remove it from history with git filter-repo. 3) Force-push and tell the team. 4) Add secret scanning.
git filter-repo --path .env --invert-paths
Q24. What are Git hooks?
Why: Hooks can stop bad commits early.
What: Hooks are scripts Git runs at events like pre-commit or pre-push.
How: Use them for lint, format and secret scans (often with the pre-commit tool).
.git/hooks/pre-commit
Q25. What is a monorepo vs multi-repo setup?
Why: It changes how pipelines are designed.
What: Monorepo: many services in one repo. Multi-repo: one repo per service.
How: Monorepos need path-based triggers; multi-repos need shared pipeline templates.
Practice tasks
Easy What is the difference between git merge and git rebase?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is the difference between git pull, git fetch and git clone?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is git stash?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is .gitignore?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy How do you resolve a merge conflict?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium What is git cherry-pick?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium How do you squash commits?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium How do you recover a deleted branch?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Homework: try at home
- Pick five questions you find hard.
- Write your own answer for each in three lines.
- Record yourself answering them. Listen once and improve.
Recap
In short
- Answer in order: why, what, how, then one example.
- Show one small command when you can.
- "Asked at" comes from public interview stories.
- Practise aloud; do not memorise word for word.
FAQ
Do I need to learn all 25 questions?
No. Start with the fresher ones. Then add the experienced ones for your level.
Should I memorise these answers?
No. Understand the why, then say it in your own words. Interviewers notice memorised lines.
What if I do not know an answer?
Say so honestly. Then explain how you would find out, step by step.
Are these questions only for one company?
No. "Asked at" shows where people said it was asked. Other companies ask the same things.
How long should an answer be?
About 30 to 60 seconds. Give a reason, a plain meaning and one example.
Is a lab really needed?
Yes. Running the command once makes your answer real and confident.
Interview questions
Practise these five first. Many companies asked them.
- What is the difference between git merge and git rebase? - Merge joins two branches with a merge commit and keeps history as it happened.
- Which branching strategy have you used? - Common ones: GitFlow (develop, release, hotfix branches), GitHub Flow (main + short feature branches), trunk-based (tiny branches, feature flags).
- How do you resolve a merge conflict? - Git stops when two branches change the same lines.
- What is the difference between git pull, git fetch and git clone? - clone copies a repo for the first time.
- What is git stash? - stash saves uncommitted changes aside and cleans the working folder.
Quick quiz
Q1. What is the difference between git merge and git rebase?
Merge joins two branches with a merge commit and keeps history as it happened.
Q2. What are Git tags and why use them?
A tag is a name for one commit, like v1.2.0.
Q3. What is the difference between Git and GitHub?
Git is the version control tool on your machine.
Q4. What is a monorepo vs multi-repo setup?
Monorepo: many services in one repo.
Samajla ka?
Revision card
Interview card
Comparison card