Git & GitHub Course
Git & GitHub
/
Advanced

Scenario-Based Questions

Definition

Interview questions framed as real-world disasters or workflows, testing your practical problem-solving skills.

Explain Like I'm New

The interviewer says: 'You committed a 2GB video file by accident. You haven't pushed yet. How do you fix this without losing your other code?'

Real World Example

Answering: 'I would use `git reset --mixed HEAD~1` to uncommit the files, add the video to `.gitignore`, and commit again.'

Common Use Cases

  • •Testing practical experience

Terminal Output

bash / terminal
/* Q: You are working on a feature branch. The boss says there is a critical bug on main that you need to fix immediately. Your current feature is half-finished and broken, so you can't commit it. What do you do? A: 1. Run `git stash` to temporarily shelve my broken feature code. 2. `git checkout main` 3. `git checkout -b hotfix-branch` 4. Fix the bug, commit, and merge it. 5. `git checkout feature-branch` 6. Run `git stash pop` to bring my broken code back to my working directory and resume working on the feature. */

Interview Questions

basic

  • You realize your last commit message had a typo. You haven't pushed yet. How do you fix the message?

intermediate

  • You pushed a broken commit to the public `main` branch. It crashed production. How do you fix it safely?

Flash Cards

Question

Fix typo?

Click to reveal answer
Answer

Use `git commit --amend -m "Corrected message"`.

Question

Fix broken public commit?

Click to reveal answer
Answer

Because it is public, you CANNOT use `reset` (which alters history). You must use `git revert <hash>`, which creates a brand new commit that performs the exact opposite actions of the broken commit, and push that.