Git is the version control system behind almost every software project, so Git questions appear in developer, DevOps and even security interviews. These Git interview questions and answers cover the core concepts, everyday commands, branching strategies and how to fix common mistakes.

Git interview questions and answers

Basics

1. What is Git?

Git is a distributed version control system. Every developer has a full copy of the repository, including its history. As a result, most operations are fast and work offline.

2. Git vs GitHub?

Git is the tool that tracks changes. GitHub, GitLab and Bitbucket are hosting platforms that add remote repositories, pull requests, issues and CI/CD.

3. Explain the three areas in Git.

  • Working directory: your files as you edit them.
  • Staging area (index): changes you have marked for the next commit with git add.
  • Repository: committed snapshots stored in the .git directory.

4. Which commands do you use every day?

git clone <url>
git status
git add file.txt
git commit -m "Describe the change"
git pull
git push
git log --oneline --graph

Branching and merging

5. How do you create and switch branches?

git switch -c feature/login     # create and switch
git switch main                 # switch back

Older guides use git checkout -b, which still works.

6. Merge vs rebase?

Merge combines branches and keeps their history, often with a merge commit. Rebase replays your commits on top of another branch, which produces a linear history. Never rebase commits that others have already pulled, because it rewrites history.

7. How do you resolve a merge conflict?

Open the conflicted files, choose the right content between the conflict markers, then git add the files and finish with git commit (or git rebase --continue).

8. Fast-forward merge vs three-way merge?

A fast-forward merge simply moves the branch pointer when there are no new commits on the target branch. A three-way merge creates a merge commit when both branches have changed.

9. What is cherry-pick?

git cherry-pick <commit> applies one specific commit from another branch, which is useful for hotfixes.

Undoing changes

10. git reset vs git revert?

  • git revert <commit> creates a new commit that undoes an earlier one. It is safe on shared branches.
  • git reset moves the branch pointer back. --soft keeps changes staged, --mixed keeps them unstaged, and --hard discards them. Use it mainly on local, unpushed work.

11. How do you fix the last commit message?

git commit --amend, but only before you push.

12. What does git stash do?

It saves uncommitted changes temporarily, so you can switch branches. Later, git stash pop restores them.

13. How do you recover a “lost” commit?

Use git reflog to find where HEAD pointed earlier, then create a branch from that commit.

Remotes and collaboration

14. git fetch vs git pull?

fetch downloads new commits without changing your branch. pull runs fetch and then merges or rebases.

15. What is a pull request?

A pull request (or merge request) proposes changes from one branch to another. Teammates review the code, and automated tests run before merging.

16. Describe common branching strategies.

  • GitHub Flow: short-lived feature branches merged into main after review.
  • Trunk-based development: very small, frequent merges to main, often with feature flags.
  • Git Flow: separate develop, release and hotfix branches; heavier, but suits scheduled releases.

Advanced and security

17. What are Git hooks?

Scripts that run at certain points, such as pre-commit to run linters or block secrets.

18. What is .gitignore?

A file that lists paths Git should not track, such as build output, logs and .env files.

19. You committed a password. What do you do?

First, rotate the secret immediately, because it may already be exposed. Then remove it from history with a tool like git filter-repo, force-push with care and ask collaborators to re-clone. Finally, add secret scanning to prevent repeats.

20. How do you find the commit that introduced a bug?

Use git bisect, which performs a binary search through history while you mark commits as good or bad.

For related DevOps topics, see our DevOps interview questions and Jenkins interview questions.

Keep preparing

Practise each answer out loud, and run the commands in a lab rather than memorising them. Interviewers often ask follow-up questions, so make sure you understand why each answer is true.

Sources

Preparing for an interview? Browse more questions in our interview preparation hub. For businesses, we also offer security services such as VAPT, server hardening and ISO 27001 readiness.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply