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 git stash, and when would you use it?

    git stash saves your uncommitted changes in a temporary stack and gives you a clean working directory, so you can switch branches or pull without committing half-done work. Later, git stash pop brings the changes back and removes them from the stack; git stash apply brings them back but keeps the stash.

    BeginnerIn-depth3 min read
  2. Does git stash save untracked files, and how do you include them?

    By default git stash saves only tracked changes. Add -u (--include-untracked) to also stash new files, or -a to include ignored files as well.

    BeginnerQuick answer1 min read
  3. How do you list, name and inspect your stashes?

    Save with git stash push -m 'message' so each stash has a label, list them with git stash list, and see their contents with git stash show -p stash@{n}.

    BeginnerQuick answer1 min read
  4. What is the difference between git stash pop and git stash apply?

    Both reapply stashed changes to your working tree. pop also deletes the stash entry afterwards, while apply keeps it, so you can reuse it on another branch.

    BeginnerQuick 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
  6. What are the risks of relying on git stash?

    Stashes are local, easy to forget, and git stash drop or clear removes them. They are not on GitHub, so a disk failure loses them. For anything you care about, commit on a temporary branch instead.

    IntermediateQuick answer1 min read