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 semantic versioning, and how do Git tags relate to it?
Semantic versioning uses MAJOR.MINOR.PATCH. Bump major for breaking changes, minor for new backward-compatible features, patch for bug fixes. Teams tag each release commit, such as v2.3.1.
BeginnerQuick answer1 min read - What is the difference between a lightweight tag and an annotated tag?
A lightweight tag is just a name pointing to a commit. An annotated tag is a full object storing the tagger, date and a message, and can be signed. Annotated tags are recommended for releases.
BeginnerQuick answer1 min read - What is the difference between git bisect and git blame?
git blame shows who last changed each line of a file and in which commit. git bisect finds which commit introduced a behavior by testing the project at different points in history.
BeginnerQuick answer1 min read - What is the difference between git diff and git diff --staged?
git diff shows changes in your working files that are not yet staged. git diff --staged shows changes already added to the staging area, which is exactly what the next commit will contain.
BeginnerQuick answer1 min read - What is the difference between git fetch and git pull?
git fetch downloads new commits from the remote and updates your origin/* references without touching your own branch. git pull does a fetch and then merges (or rebases) the result into your current branch.
BeginnerQuick answer1 min read - What is the difference between git init and git clone?
git init turns the current folder into a new, empty repository. git clone copies an existing repository, including its full history, from a URL, and also sets up the origin remote for you.
BeginnerQuick answer1 min read - What is the difference between git reset --soft, --mixed and --hard?
All three move the branch to another commit. --soft keeps your changes staged, --mixed (the default) keeps them but unstaged, and --hard throws them away completely.
BeginnerQuick answer1 min read - 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 - What is the golden rule of rebasing?
Never rebase commits that other people have already pulled. Rebase creates new commits with new hashes, so teammates who have the old ones end up with duplicated or conflicting history.
BeginnerQuick answer1 min read - What is the staging area in Git, and why does it exist?
The staging area (index) is a holding zone between your working files and the next commit. git add puts chosen changes there, so a commit contains exactly what you picked rather than everything you touched.
BeginnerQuick answer1 min read - What kinds of files should you put in .gitignore?
Generated, secret or machine-specific files: dependencies like node_modules, build output, logs, .env files, and editor or OS clutter. Source code and configuration the team needs must stay tracked.
BeginnerQuick answer1 min read - What makes a good Git commit message?
A short imperative summary line of about 50 characters, a blank line, then an optional body explaining why the change was made. Describe the reason, not just what the diff already shows.
BeginnerQuick answer1 min read - Why are commit messages written in the imperative mood?
Git's own messages, like 'Merge branch' or 'Revert commit', are imperative, and the convention completes the sentence 'If applied, this commit will...'. It keeps the log consistent and short.
BeginnerQuick answer1 min read - Why does git push get rejected with 'non-fast-forward', and what should you do?
The remote branch has commits you do not have, so your push would overwrite them. Pull (or fetch and rebase) first to combine the work, then push again. Do not force-push over shared work.
BeginnerQuick answer1 min read - Why don't tags appear on GitHub after git push, and how do you push them?
git push does not send tags by default. Push one with git push origin v1.0, or all with git push --tags. Tags are not created on the remote until you do this.
BeginnerQuick answer1 min read - Why is the submodule folder empty after cloning, and how do you fix it?
A normal clone does not download submodule contents. Run git submodule update --init --recursive, or clone with git clone --recurse-submodules next time.
BeginnerQuick answer1 min read