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. How do you resolve a merge conflict in Git?

    Run git status to see the conflicted files, open each one and find the markers <<<<<<<, ======= and >>>>>>>. Edit the code to the correct final version, delete the markers, then git add the file and run git commit (or git rebase --continue during a rebase). Test before you push.

    BeginnerIn-depth3 min read
  2. What is a pull request, and how does the code review workflow work?

    A pull request (PR) is a request to merge your branch into another branch, usually main. You push a branch, open a PR with a clear description, automated checks run, teammates review and comment, you push fixes, and once approved the PR is merged and the branch deleted.

    BeginnerIn-depth3 min read
  3. What is git stash, and when would you use it?

    git stash saves your uncommitted changes in a temporary stack and gives you a clean working directory, so you can switch branches or pull without committing half-done work. Later, git stash pop brings the changes back and removes them from the stack; git stash apply brings them back but keeps the stash.

    BeginnerIn-depth3 min read
  4. What is the difference between Git and GitHub?

    Git is a version control tool that runs on your own computer and records the history of your code. GitHub is a website that hosts Git repositories online and adds collaboration features like pull requests, code review, issues and CI. You can use Git without GitHub, but GitHub is built on top of Git.

    BeginnerIn-depth3 min read
  5. 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
  6. 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
  7. 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
  8. What branching strategies do teams use in Git? Compare GitFlow and trunk-based development.

    Most teams use short-lived feature branches merged through pull requests. GitFlow adds long-lived develop, release and hotfix branches and suits planned, versioned releases. Trunk-based development keeps everyone merging small changes into main at least daily, using CI and feature flags, and suits teams that deploy often.

    AdvancedIn-depth3 min read