Interview Q&A / Git & GitHub
Git & GitHub interview questions
Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.
Prefer rapid revision? Practise Git & GitHub short interview answers →
- How do you undo a commit that you already pushed to a shared branch?
Use git revert, which adds a new commit that cancels the bad one. History is not rewritten, so teammates can pull normally. Avoid reset plus force-push on shared branches.
BeginnerQuick answer1 min read - How do you unstage a file you added by mistake?
Use git restore --staged file, or the older git reset HEAD file. The file leaves the staging area but your edits stay in the working directory.
BeginnerQuick answer1 min read - What is the difference between git reset --soft, --mixed and --hard?
All three move the branch to another commit. --soft keeps your changes staged, --mixed (the default) keeps them but unstaged, and --hard throws them away completely.
BeginnerQuick answer1 min read