Git & collaboration interview questions
8 questions across 2 sections, in the order you would learn them. Every answer here is one that works — but an answer you have read is not an answer you can give, so use Test yourself and say it out loud first.
Git as you actually use it
Read the section that teaches thisIf this comes up in an interview
What is a branch in git?
A file containing one commit hash, plus an entry in HEAD saying which branch you are on. The commits are not stored in the branch, so creating and deleting branches is instant and costs nothing, and deleting one does not delete any commits.
Then they push further
Then why does rebasing change the commit hashes?
A commit's id is a hash of its contents, its metadata and its parent. Rebase gives the commits a different parent, so they hash differently. The originals are still on disk until they are garbage collected, which is why the reflog can get them back.
What gets marked up. Strong answers describe the graph and the pointer. Describing a branch as a copy of the code is the answer that predicts trouble later.
What is the difference between git reset --soft, --mixed and --hard?
All three move the current branch to the commit you name. Soft leaves your files and the staging area alone, so the changes from the undone commits are staged and ready to recommit. Mixed, the default, leaves your files alone but unstages. Hard overwrites your files from the commit, and is the only one of the three that can destroy work that was never committed.
What is the difference between merge and rebase?
Merge combines two histories and adds a merge commit, preserving what actually happened. Rebase replays your commits on top of the target, producing a linear history but rewriting the commits. Never rebase anything already pushed and pulled by others.
How do you undo a commit that is already on the shared branch?
git revert, which adds a new commit undoing the change. Reset rewrites history and breaks everyone who already pulled it.
How would you find which commit introduced a bug?
git bisect. Mark a known good commit and a known bad one, and it binary searches the range, so a thousand commits takes about ten checks.
Why not commit model weights to git?
Git stores a full copy of every version of a binary, so the repository grows enormously and clones become impractical. Store weights in object storage with a versioned path and commit the reference instead.
When something goes wrong in git
Read the section that teaches thisIf this comes up in an interview
You pushed an API key to a public repository. What do you do?
Revoke the key and issue a new one first, because it may already have been copied by automated scanners within minutes. Then remove it from the code and, if needed, from history, and add secret scanning to prevent a repeat. Check the provider's logs for misuse.
Then they push further
Why is deleting the commit not enough?
Anyone who cloned or scanned the repository already has it, forks keep it, and caches may too. Only revoking the key removes the risk.
What gets marked up. Revoking first is the whole answer. Candidates who start with rewriting history are marked down.
What is the difference between reset and revert?
Reset moves the branch pointer back, rewriting history, which is fine for local commits. Revert makes a new commit that undoes an earlier one, keeping history intact, which is what you use on shared branches.
These are the questions for one topic. The whole question bank covers every topic on the site.