← Back to Blog
Git & GitHub Interview Questions 2026: The Complete Guide
Git15 min read·May 12, 2026
By InterviewDrill Team

Git & GitHub Interview Questions 2026: The Complete Guide

Version control is foundational. Interviews test if you know how to safely fix mistakes and manage branch strategies at scale.


1. What is the difference between git merge and git rebase?

git merge: Takes the contents of a source branch and integrates it with a target branch. It preserves the exact history and chronological order of commits. Creates a new "merge commit".

git rebase: Moves or combines a sequence of commits to a new base commit. It rewrites the commit history by creating brand new commits for each commit in the original branch.

When to use which: Use \merge\ to preserve history of a feature branch. Use \rebase\ to keep a linear project history.

2. You accidentally committed a secret. How do you remove it?

If you just committed it locally and haven't pushed: \git reset --soft HEAD~1\, remove the secret, then commit again.

If pushed: You must use a tool like BFG Repo-Cleaner or \git filter-repo\ to rewrite the entire history and remove the file. Then force push: \git push --force\. Rotate the secret immediately.

3. What is a detached HEAD state?

A detached HEAD state occurs when you checkout a specific commit rather than a branch. You can make experimental changes here, but they will be lost if you switch away unless you create a new branch from this state using \git checkout -b \.

4. How do you squash multiple commits into one?

You can use interactive rebase: \git rebase -i HEAD~N\ where N is the number of commits. Change the word \pick\ to \squash\ (or \s\) for the commits you want to combine into the one above them.

5. What does git cherry-pick do?

It applies the changes introduced by some existing commits to the current branch. It is useful when you want to port a specific bug fix or feature from one branch to another without merging the entire branch.

6. What is the difference between git fetch and git pull?

\git fetch\ downloads commits, files, and refs from a remote repository into your local repo, but it does not update your working directory.

\git pull\ is a combination of \git fetch\ and \git merge\. It fetches the changes and immediately merges them into your current branch.

7. How do you find which commit introduced a bug?

Use \git bisect\. It performs a binary search through the commit history to find the exact commit that introduced a bug. You mark a known "good" commit and a known "bad" commit, and Git checks out intermediate commits for you to test.

8. What is the Git stash?

The stash is a temporary storage area for changes that you are not ready to commit. \git stash\ saves your modified tracked files and staged changes, giving you a clean working directory. Use \git stash pop\ to apply the stashed changes back.

9. How do you resolve a merge conflict?

Open the conflicted files, look for the conflict markers (\<<<<<<<\, \=======\, \>>>>>>>\), and manually edit the file to keep the desired changes. After editing, use \git add\ on the resolved files and then run \git commit\.

10. What is a Git hook?

Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle (e.g., \pre-commit\, \pre-push\).

11. Explain the difference between git reset and git revert.

\git reset\ moves the branch pointer backward, effectively erasing commits from history (good for local, unpushed changes).

\git revert\ creates a new commit that undoes the changes of a previous commit, preserving history (safe for shared branches).

12. How do you change the message of the most recent commit?

Run \git commit --amend -m "New commit message"\. Note: only do this if you haven't pushed the commit yet, otherwise you will have to force push.

13. What is git reflog?

It is a mechanism to record when the tip of branches and other references were updated in the local repository. It is extremely useful for recovering "lost" commits or branches that have been accidentally deleted or reset.

14. What is a fast-forward merge?

When the current branch has not diverged from the target branch, Git just moves the pointer forward instead of creating a new merge commit. This keeps the history perfectly linear.

15. How do you recover a deleted branch?

If you haven't garbage collected, you can find the SHA of the tip of the deleted branch using \git reflog\, and then recreate the branch with \git checkout -b \.

16. What is git worktree?

\git worktree\ allows you to have multiple working directories linked to a single Git repository. This is useful for working on multiple branches simultaneously without needing to clone the repo multiple times or constantly stash changes.

17. How do you ignore tracked files locally?

If a file is already tracked but you want to ignore local modifications without adding it to \.gitignore\, use \git update-index --assume-unchanged \.

18. What are Git submodules?

Submodules allow you to keep another Git repository in a subdirectory of your repository. It lets you clone another repository into your project and keep your commits separate.

19. How do you rewrite authorship of past commits?

You can use \git filter-repo\ or an interactive rebase (\git rebase -i\) and use the \edit\ command on the commits, then run \git commit --amend --author="New Name "\.

20. What is GitHub Actions?

GitHub Actions is a CI/CD platform integrated into GitHub that allows you to automate your build, test, and deployment pipeline. Workflows are defined in YAML files located in the \.github/workflows\ directory.

Reading helps. Practicing wins interviews.

Practice these exact questions with an AI interviewer that pushes back. First session completely free.

Start Practicing Free →
← Previous
Site Reliability Engineering (SRE) Interview Questions 2026
Next →
GitOps & ArgoCD Interview Questions for DevOps Engineers

Related articles

AWS DevOps Interview Questions 2026: The Complete Guide
AWS
AWS DevOps Interview Questions 2026: The Complete Guide
How to Crack a Kubernetes Interview in 2026
Kubernetes
How to Crack a Kubernetes Interview in 2026
System Design Interview Guide for Cloud Engineers (2026)
System Design
System Design Interview Guide for Cloud Engineers (2026)
Terraform Interview Questions 2026: The Complete Guide
Terraform
Terraform Interview Questions 2026: The Complete Guide