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. How do you delete a branch locally and on the remote?

    Delete it locally with git branch -d name (or -D to force), and delete it on the remote with git push origin --delete name. They are separate; removing one does not remove the other.

    BeginnerQuick answer1 min read
  2. How do you find which branches are already merged into main?

    Run git branch --merged main to list branches whose commits are all in main, and git branch --no-merged main for the rest. Merged ones are usually safe to delete.

    BeginnerQuick answer1 min read
  3. How do you rename a Git branch, including one already pushed?

    Locally use git branch -m old new. For a pushed branch, push the new name, set its upstream, and delete the old name on the remote. Tell teammates, since their copies still track the old name.

    BeginnerQuick answer1 min read
  4. How can you recover a branch that you deleted by mistake?

    Find the branch's last commit hash with git reflog, then recreate it with git branch name hash. The commits are not erased immediately, so recovery works until Git garbage-collects them.

    IntermediateQuick answer1 min read
  5. How can you turn a stash into its own branch?

    Run git stash branch new-name. Git creates the branch at the commit where you stashed, applies the stash there, and drops it, which avoids conflicts if the original branch has moved on.

    IntermediateQuick answer1 min read