🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

Git Interview Questions 2026: Merge, Rebase, Reset and Branching

⏱️4 min read  ·  826 words

Git interview questions test your understanding of version control concepts, branching strategies, merge vs rebase, and collaborative workflows. This guide covers the most commonly asked Git questions for software developer interviews in 2026.

Core Git Questions

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

# merge: combines two branches, preserves full history
git checkout feature
git merge main
# Creates a merge commit — shows when branches diverged

# rebase: moves/replays commits on top of another branch
git checkout feature
git rebase main
# Linear history — as if feature branched off current main

# When to use merge:
# - Integrating feature branches to main (preserves history)
# - Public/shared branches (never rebase!)
# - When you want to see branch history

# When to use rebase:
# - Keeping feature branch up to date with main
# - Cleaning up local commits before PR
# - Squashing minor fix commits

# Golden rule: never rebase commits that have been pushed to shared branches

2. What is HEAD and what is a detached HEAD?

# HEAD = pointer to current commit (usually points to branch tip)
cat .git/HEAD  # ref: refs/heads/main  (pointing to main branch)

# Detached HEAD: HEAD points directly to a commit, not a branch
git checkout abc123  # checking out a specific commit
# HEAD is now at abc123 (detached)
# Any commits made won't belong to any branch!

# To save work in detached HEAD:
git checkout -b new-branch  # create branch from current position

# Common cause: git checkout <tag> or git checkout <commit-hash>

3. Explain git reset vs git revert

# git reset: move HEAD backward (rewrites history)
git reset --soft HEAD~1    # undo commit, keep changes staged
git reset --mixed HEAD~1   # undo commit, keep changes unstaged (DEFAULT)
git reset --hard HEAD~1    # undo commit AND discard changes (DESTRUCTIVE)

# NEVER use --hard on shared branches!

# git revert: create a new commit that undoes a previous commit
git revert abc123          # safe for shared branches
# Creates commit: "Revert 'feature: add user auth'"

# Use reset for: local commits you want to undo
# Use revert for: commits already pushed to shared branches

4. What is git stash and when do you use it?

# Temporarily save uncommitted changes
git stash push -m "WIP: half-done feature"
git stash list                           # see all stashes
git stash pop                            # apply latest + remove
git stash apply stash@{0}               # apply without removing
git stash drop stash@{0}               # delete a stash

# Stash specific files
git stash push -m "CSS fix" -- styles.css components/Button.css

# Include untracked files
git stash push -u -m "including new files"

# Common workflow:
# 1. Working on feature-A
# 2. Urgent fix needed on feature-B
# git stash (save feature-A work)
# git checkout feature-B
# ... fix ...
# git checkout feature-A
# git stash pop (restore feature-A work)

5. How do you squash multiple commits?

# Interactive rebase — squash last 3 commits
git rebase -i HEAD~3

# Editor opens:
# pick abc123 feat: add login form
# pick def456 fix: correct validation
# pick ghi789 fix: typo in error message

# Change to:
# pick abc123 feat: add login form
# squash def456 fix: correct validation
# squash ghi789 fix: typo in error message

# Result: one clean commit with combined message

# Alternative: squash merge (GitHub/GitLab button)
# When merging PR, select "Squash and merge"
# All commits become one commit in main

6. What is cherry-pick?

# Apply a specific commit from another branch
git log --oneline feature-branch  # find the commit hash
git cherry-pick abc123            # apply just that commit

# Common use: apply a hotfix to multiple release branches
git checkout release/2.0
git cherry-pick fix/critical-bug-abc123
git checkout release/1.9
git cherry-pick fix/critical-bug-abc123

# Cherry-pick a range
git cherry-pick abc123..def456  # applies all commits in range

# If conflicts arise
git cherry-pick --continue  # after resolving conflicts
git cherry-pick --abort     # cancel cherry-pick

7. Explain branching strategies

GitFlow (complex, stable releases):
  main          — production
  develop       — integration
  feature/xxx   — feature branches
  release/1.0   — release preparation
  hotfix/xxx    — urgent fixes

GitHub Flow (simple, continuous delivery):
  main          — always deployable
  feature/xxx   — short-lived feature branches
  Pull Request → Code Review → Merge to main → Deploy

Trunk-Based Development (very short-lived branches):
  main (trunk)  — everyone commits daily
  feature/xxx   — max 1-2 days old, use feature flags

2026 recommendation: GitHub Flow or Trunk-Based for most teams

8. What is .gitignore and why is it important?

# .gitignore tells git which files to ignore
# Never commit:
# - Secrets/credentials (.env files!)
# - Dependencies (node_modules/, vendor/)
# - Build artifacts (dist/, __pycache__/)
# - OS files (.DS_Store, Thumbs.db)
# - IDE files (.idea/, .vscode/ — optional)

# Example .gitignore
*.env
*.env.*
node_modules/
dist/
build/
.DS_Store
__pycache__/
*.pyc
*.pem
*.key

# Already committed? Remove from tracking:
git rm --cached .env        # stop tracking but keep file
git rm -r --cached dist/    # stop tracking directory

# Global gitignore (applies to all repos)
git config --global core.excludesfile ~/.gitignore_global

Git interview success: understand the history model (commits, branches, HEAD), know the difference between merge and rebase and when to use each, explain reset vs revert clearly, and demonstrate knowledge of team workflows (GitHub Flow, GitFlow). Practice on real repositories — reading git history is easier than describing it theoretically.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা