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 .gitignore, and what would you do if you accidentally committed a password or API key?

    .gitignore lists files Git should not track, like .env, node_modules and build output. If a secret was committed, first revoke or rotate it, because anyone who saw it can use it. Then stop tracking the file, add it to .gitignore, and if it was pushed, remove it from history with git filter-repo or BFG and force push.

    IntermediateIn-depth4 min read
  2. What is the difference between git merge and git rebase?

    Both bring changes from one branch into another. Merge joins the two histories with a new merge commit and keeps everything as it happened. Rebase replays your commits on top of the other branch, giving a straight, linear history but rewriting commit IDs. Never rebase commits that others have already pulled.

    IntermediateIn-depth3 min read
  3. 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