INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 31–45 of 229 questions
31.What does git stash do?MidGit
It saves your uncommitted changes and gives you a clean working directory, so you can switch branches. git stash pop brings them back; git stash list shows saved stashes.
32.How do you squash several commits into one?MidGit
Use an interactive rebase: git rebase -i HEAD~4 and mark commits as squash or fixup. Many teams use 'squash and merge' in the pull request instead. Only rewrite commits that aren't shared yet.
33.What is git cherry-pick and when is it useful?MidGit
It copies one commit onto your current branch, for example to bring a hotfix from main into a release branch. Use it for a few commits; for many, merge or rebase instead.
34.What are Git hooks?MidGit
Scripts Git runs at certain moments, such as pre-commit or commit-msg. Teams use them (often through the pre-commit framework) to run linters, formatters and secret scanners before code leaves a laptop. Enforce the same checks in CI too, because local hooks can be skipped.
35.What branching strategy would you choose and why?SeniorGit
Usually trunk-based development: short-lived branches merged to main several times a day, feature flags for unfinished work, and releases cut from main with tags. GitFlow suits slow, versioned releases but adds merge overhead.
36.How do you recover a branch you deleted by mistake?SeniorGit
git reflog shows where HEAD has been; find the last commit of the branch and run git branch name <sha>. Commits stay recoverable until garbage collection prunes them.
37.How do you handle a huge repository that is slow to clone?SeniorGit
Use shallow clones (--depth 1) in CI, partial clones (--filter=blob:none) and sparse checkout for monorepos. Move large binaries to Git LFS or an artifact store, and clean old large files out of history with git filter-repo if needed.
38.What is trunk-based development, and what does it need to work?SeniorGit
Everyone merges small changes into main at least daily instead of keeping long-lived branches. It needs fast CI, good automated tests, feature flags to hide unfinished work, and code review that happens quickly.
39.How do you protect the main branch?SeniorGit
Use branch protection: no direct pushes, required pull request reviews (and CODEOWNERS), required passing CI checks, signed commits if needed, and no force pushes. Combine with secret scanning on push.
40.How does Git store data internally?SeniorGit
Git is a content-addressed store of objects: blobs (file content), trees (folders), commits (a tree plus parents and metadata) and tags. Each object is named by its hash. Branches are just files that point to a commit hash.
41.Why use a virtual environment?BeginnerPython for DevOps
It gives each project its own Python packages, so versions never clash between projects and your system Python stays clean.
42.What is the difference between a list and a dict?BeginnerPython for DevOps
A list is an ordered group of items you reach by position. A dict stores values under names (keys), so you reach them by key.
43.How do you read a file safely?BeginnerPython for DevOps
Use a with block: with open(path) as f. It closes the file even when an error happens. pathlib makes paths work on every system.
44.What does exit code 0 mean?BeginnerPython for DevOps
Success. Any other number means failure. CI systems and shells read this number, so scripts should exit non-zero when they fail.
45.Why is shell=True dangerous in subprocess?MidPython for DevOps
The text is parsed by a shell, so special characters from outside input can run extra commands. Pass the command as a list of arguments instead.