LearnDevOpsHands-On Labs
Back to All Interview Tracks
26 QuestionsDevOps & Cloud

Git Interview Questions

26 Git questions from real DevOps interviews, sorted by seniority: merge against rebase, reset against revert, the reflog, detached HEAD, submodules, and cherry-pick.

Merge vs RebaseSoft vs Hard ResetGit Reflog RecoveryDetached HEADCherry-pick & ConflictSubmodules & Worktrees
Showing 26 of 26 questions
•
#1

What is a Git commit, and what is a Git branch?

Junior

A commit is an immutable snapshot of the whole tree, plus metadata: author, message, timestamp, and one or more parent commit hashes. It is not a diff. Git computes diffs on demand by comparing snapshots.

A branch is a forty-byte file containing a commit hash. That is all. git branch feature writes one file; it copies nothing.

That is why branching in Git is instant while it was expensive in older systems, and why the chain of parent pointers is the history rather than the branch names.

HEAD is a pointer to the branch you are on, which is in turn a pointer to a commit. Committing moves the branch pointer forward; HEAD follows because it points at the branch.

Being able to say "a branch is a movable label on a commit" answers a surprising number of later questions on its own.

link
#2

What is the Git staging area for?

#3

What is the difference between git fetch and git pull?

#4

How do you change the last Git commit?

#5

What is the difference between git merge and git rebase?

#6

What is the difference between git reset --soft, --mixed and --hard?

#7

When would you use git revert rather than git reset?

#8

Your git push is rejected as non-fast-forward. What do you do?

#9

How do you resolve a Git merge conflict?

#10

How do you clean up Git commits before opening a pull request?

#11

What does git cherry-pick do, and when is it the right tool?

#12

What does git stash do, and what are its limits?

#13

What is the Git reflog, and how does it save you?

#14

What happens when you are in detached HEAD state in Git?

#15

Someone force-pushed over the shared branch. How do you recover?

#16

How does git bisect work, and when would you use it?

#17

Which Git branching strategy would you choose for a team, and why?

#18

What is the difference between a Git submodule and a subtree?

#19

What is the difference between git push --force and --force-with-lease?

#20

What is a .gitignore file, and why does it not work on already-tracked files?

#21

How do you find which Git commit introduced a specific line?

#22

What are the four Git object types, and how do they fit together?

#23

What are Git hooks, and what would you use them for?

#24

How do you undo changes to a file in Git before committing?

#25

What is the difference between a Git tag and a branch, and what is an annotated tag?

#26

How would you remove a committed secret from a Git repository?