Interview Q&A / Git & GitHub

INTERVIEW Q&A · 97 QUESTIONS

Git & GitHub interview questions

Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.

  1. What is the difference between git reset and git revert?

    git revert makes a new commit that undoes an earlier commit, so history is kept and it is safe on shared branches. git reset moves your branch pointer back to an older commit and removes the later commits from the branch; --soft keeps the changes staged, --mixed keeps them unstaged, and --hard throws them away. Use reset only on local, unpushed work.

    IntermediateIn-depth3 min read
  2. 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
  3. 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
  4. 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
  5. What does git restore do, and how is it different from git checkout for files?

    git restore discards changes in a file or unstages it. It was added in Git 2.23 to split the file-restoring job away from git checkout, which also switched branches and confused beginners.

    IntermediateQuick answer1 min read