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 a merge commit, and how is it different from a normal commit?

    A merge commit has two (or more) parents instead of one. It records the point where two lines of history were joined, and holds the combined result of both branches.

    BeginnerQuick answer1 min read
  2. What is an upstream branch in Git?

    An upstream branch is the remote branch that your local branch is linked to. With it set, plain git pull, git push and git status know where to send and compare changes without extra arguments.

    BeginnerQuick answer1 min read
  3. What is branch protection on GitHub, and what rules can you set?

    Branch protection rules guard important branches like main. You can require pull requests, a number of approvals, passing status checks, up-to-date branches, and block force pushes and deletion.

    BeginnerQuick answer1 min read
  4. What is GitHub Actions?

    GitHub Actions is GitHub's built-in automation. A workflow, written in a YAML file under .github/workflows, runs jobs on GitHub-hosted machines when events like a push or pull request occur, commonly for tests, builds and deployment.

    BeginnerQuick answer1 min read
  5. What is HEAD in Git?

    HEAD is a pointer to the commit you currently have checked out. Normally it points to a branch name, which points to that branch's latest commit, so HEAD marks where your next commit will be added.

    BeginnerQuick answer1 min read
  6. What is origin in Git, and can a repo have more than one remote?

    origin is the default name Git gives to the remote you cloned from. It is just a nickname for a URL, and a repository can have many remotes, such as origin and upstream for a fork.

    BeginnerQuick answer1 min read
  7. 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
  8. What is the difference between a fork, a clone and a branch?

    A fork is your own server-side copy of someone else's GitHub repository. A clone is a local copy on your computer. A branch is a separate line of work inside one repository.

    BeginnerQuick answer1 min read
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. What makes a good GitHub issue?

    A clear title, the steps to reproduce, expected versus actual behaviour, environment details, and screenshots or logs. For features, state the problem and the outcome wanted, not only a solution.

    BeginnerQuick answer1 min read
  21. 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
  22. 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
  23. 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
  24. 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