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 push --force and --force-with-lease?

    --force overwrites the remote branch no matter what. --force-with-lease overwrites only if the remote is still where you last saw it, so you do not wipe out commits a teammate pushed meanwhile.

    IntermediateQuick answer1 min read
  2. What is the difference between squash and fixup in an interactive rebase?

    Both merge a commit into the one above it. squash lets you combine and edit the two commit messages, while fixup silently discards the second message and keeps the first as it is.

    IntermediateQuick answer1 min read
  3. When is cherry-pick a bad idea?

    Overusing it creates duplicate commits with different hashes, which later cause confusing conflicts when the branches are merged. Prefer merging or rebasing when you want the whole branch.

    IntermediateQuick answer1 min read
  4. When would you use git restore instead of git reset?

    Use git restore to change files, either discarding edits or unstaging a path. Use git reset to move the branch pointer to another commit. Restore never moves your branch.

    IntermediateQuick answer1 min read
  5. Why does .gitignore not work for a file that is already tracked?

    Git ignores only untracked files. If a file was committed earlier, it stays tracked despite the rule. Run git rm --cached file to stop tracking it, then commit; the file remains on disk.

    IntermediateQuick answer1 min read
  6. Why is a submodule in detached HEAD state, and is that a problem?

    The parent pins an exact commit, so Git checks the submodule out at that commit, not on a branch. It is normal. To edit the submodule, check out a branch inside it first, or commits can get lost.

    IntermediateQuick answer1 min read