Learn Git & GitHub core architecture, production scenario-based questions, incident response, and real-world engineering solutions.
β Q1: What is Git, and how does its distributed model differ from older centralized version control systems?
Click on the dropdown below to reveal the technical answer.
Answer: Git is a free, open-source distributed version control system (DVCS) designed to handle everything from small to very large projects with speed and efficiency. Unlike older centralized systems (like SVN or CVS), every Git clone is a full-fledged repository with complete history and full version-tracking capabilities, independent of network access or a central server.
β Q1a: What is version control, and why is it considered the absolute starting point for any DevOps pipeline?
Click on the dropdown below to reveal the technical answer.
Answer: Version Control is a system that records changes to a file or set of files over time, allowing developers to recall specific versions, track history, revert mistakes, and collaborate concurrently on the same codebase. It is a core pillar of DevOps because it:
β Q2: Can you explain the main architectural areas of Git? How do files transition between them?
Click on the dropdown below to reveal the technical answer.
Answer: Git architecture is divided into three local areas (often called the Git directory structure) and a remote area:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LOCAL MACHINE β
β β
β βββββββββββββββββββ git add βββββββββββββββββββββ β
β βWorking Directoryβ βββββββββ> β Staging Area β β
β β (Modified Files)β <βββββββββ β (Index) β β
β βββββββββββββββββββ git restoreβββββββββββ¬ββββββββββ β
β β² β β
β β β git commit β
β β git checkout/switch βΌ β
β ββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ β
β β Local Repository β β
β β (.git) β β
β ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββ
β
git push β git fetch/pull
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Remote Repository β
β (GitHub/GitLab) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
.git metadata database directory where Git stores committed snapshots of your project. Files here are committed.β Q3: How do you explain the difference between Git and GitHub to a non-technical stakeholder?
Click on the dropdown below to reveal the technical answer.
Answer:
β Q4: What actually happens under the hood when we execute a 'git commit' command?
Click on the dropdown below to reveal the technical answer.
Answer:
When you execute git commit -m "commit message", Git performs several actions behind the scenes:
β Q5: What is a Git object? Can you name the four primary object types stored in the database?
Click on the dropdown below to reveal the technical answer.
Answer:
Git is a content-addressable key-value database stored inside the .git/objects directory. All data is compressed and indexed by a 40-character SHA-1 hash. There are four primary types of Git objects:
β Q6: What is a Git branch under the hood? Does creating a branch duplicate our files?
Click on the dropdown below to reveal the technical answer.
Answer: In Git, a branch is not a duplicate directory copy; it is simply a lightweight, mutable pointer to a specific commit.
.git/refs/heads/ containing the 40-character SHA-1 hash of the commit you branched from.β Q7: How do you explain the difference between 'git merge' and 'git rebase'? What is the Golden Rule of Rebasing?
Click on the dropdown below to reveal the technical answer.
Answer: Both commands integrate changes from one branch into another, but they do it in fundamentally different ways:
Initial State:
A---B---C (main)
\
D---E (feature)
After git merge main into feature:
A---B---C (main)
\ \
D---E---F (feature, F is a merge commit)
After git rebase main on feature:
A---B---C (main)
\
D'---E' (feature, commits D and E are rewritten)
β Q8: What is 'cherry-picking' in Git, and can you describe a scenario where you would use it?
Click on the dropdown below to reveal the technical answer.
Answer:
git cherry-pick <commit-hash> is a command that allows you to select a specific commit from one branch and apply its changes as a new commit onto your current active branch.
β Q9: What is a 'squash merge' and why is it useful when merging Pull Requests into a main branch?
Click on the dropdown below to reveal the technical answer.
Answer:
A squash merge takes all the individual commits from a feature branch, condenses (squashes) them into a single commit, and applies that single commit onto the target branch (e.g., main).
β Q10: What is a 'fast-forward' merge? How can we prevent Git from doing this automatically?
Click on the dropdown below to reveal the technical answer.
Answer:
A fast-forward merge occurs when you merge a branch (e.g., feature) into a target branch (e.g., main), and the target branch has no new commits since the feature branch was created.
git merge --no-ff <branch>, which forces Git to create a merge commit, preserving the visual branch boundary in the history log.β Q11: Can you contrast reset, revert, and restore? Which one is safest for shared remote branches?
Click on the dropdown below to reveal the technical answer.
Answer: These commands are used to undo changes at different stages of the Git lifecycle:
--soft: Keeps changes in the Working Directory and Staging Area.--mixed (default): Keeps changes in the Working Directory but clears the Staging Area.--hard: Discards all changes in the Working Directory and Staging Area, matching the target commit exactly.β Q12: If I run a 'git reset --hard' and lose my last three commits, how would you recover them?
Click on the dropdown below to reveal the technical answer.
Answer:
Even if a commit is deleted (e.g., via git reset --hard or branch deletion), the commit object remains in the .git/objects database for a period (usually 30 days) before Git's garbage collector (git gc) purges it.
git reflog to view the history of HEAD pointer updates. Find the SHA-1 hash of the commit before the reset/deletion occurred.git show <commit-hash>.git branch recovery-branch <commit-hash>.git reset --hard <commit-hash>.β Q13: What is 'git reflog' and how does it differ from 'git log'?
Click on the dropdown below to reveal the technical answer.
Answer:
git reflog (reference log) is a local tracking mechanism that records every update made to local branch pointers and the HEAD pointer.
Unlike git log (which only shows the commit graph of the active branch), git reflog tracks commits, resets, checkouts, rebases, and merges. It acts as an undo history log for your local repository, allowing you to recover lost commits and branches.
β Q14: What does it mean to be in a 'detached HEAD' state? How do we fix it and preserve our work?
Click on the dropdown below to reveal the technical answer.
Answer: A detached HEAD state occurs when the HEAD pointer points directly to a specific commit hash rather than to a branch pointer.
git checkout <commit-hash> instead of git checkout <branch-name>.git switch -c new-branch-name.β Q15: How do you recover a local branch that was accidentally deleted using 'git branch -D'?
Click on the dropdown below to reveal the technical answer.
Answer: A deleted branch is simply a deleted pointer file. The underlying commits still exist.
git reflog and locate the hash of the latest commit on the branch before it was deleted (usually labeled checkout: moving from <branch> to ...).git checkout -b <branch-name> <commit-hash>.β Q16: What actually triggers a merge conflict in Git?
Click on the dropdown below to reveal the technical answer.
Answer: A merge conflict occurs when Git attempts to merge two branches, and changes in the branches conflict on the same lines of the same files, or a file was modified in one branch and deleted in the other. Git cannot automatically determine which version to keep and halts the merge process to request manual resolution.
β Q17: Walk me through your step-by-step process for resolving a merge conflict.
Click on the dropdown below to reveal the technical answer.
Answer: Resolving merge conflicts involves a structured process:
git status to view files marked both modified.<<<<<<< HEAD
Changes on the current active branch (e.g., main)
=======
Changes from the branch being merged in (e.g., feature)
git add <file-name>.git commit -m "merge and resolve conflicts".β Q18: Can you explain Git Flow? What are the roles of the main, develop, feature, release, and hotfix branches?
Click on the dropdown below to reveal the technical answer.
Answer: Git Flow is a structured branching model designed for project releases. It uses dedicated branches with specific roles:
main: Holds the stable production-ready code.develop: The primary integration branch for features.feature/*: Temporary branches branched from develop for new features; merged back into develop.release/*: Branches used to prepare for a new production release, allowing for final bug fixes; merged into both main and develop.hotfix/*: Branches created directly from main to address critical production issues; merged back into both main and develop.β Q19: What is GitHub Flow, and how does it compare to Git Flow for SaaS deployment models?
Click on the dropdown below to reveal the technical answer.
Answer: GitHub Flow is a lightweight, agile branching model designed for continuous deployment environments.
main to create a descriptive feature branch (e.g., update-login-ui).main once tests pass, automatically triggering deployment to production.β Q20: What is Trunk-Based Development, and how do feature flags enable it?
Click on the dropdown below to reveal the technical answer.
Answer:
Trunk-Based Development is a branching strategy where developers commit small, frequent changes to a single branchβthe "trunk" (usually main)βmultiple times a day.