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. What does git revert -n (--no-commit) do?

    It applies the reverse of a commit to your working tree and index without committing. This lets you revert several commits and record them together as a single commit.

    AdvancedQuick answer1 min read