Interview Q&A / Git & GitHub
Git & GitHub interview questions
Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.
Prefer rapid revision? Practise Git & GitHub short interview answers →
- 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 - How do you find out which rule is ignoring a file?
Run git check-ignore -v path. It prints the file, line number and pattern of the rule that matches, which helps when a file unexpectedly does not show up in git status.
IntermediateQuick answer1 min read - What is the difference between a project .gitignore and a global gitignore?
The project .gitignore is committed and shared with the team. A global gitignore, set through core.excludesFile, applies to every repo on your machine and holds personal clutter like editor folders and OS files.
IntermediateQuick answer1 min read - 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