APURV
  • Home
  • Journey
  • Projects
  • Blogs
  • Interview
  • Exams
Resume
APURV

Building scalable, secure, and production-ready cloud infrastructure. Automation first.

NAVIGATION

HomeExperienceProjectsCertificationsSkills

TECH STACK

AWSGCPK8sCI/CDLinuxDocker

CONNECT

LinkedInGitHubEmailResume

Β© 2026 Apurv Gujjar. All rights reserved.
APURV
  • Home
  • Journey
  • Projects
  • Blogs
  • Interview
  • Exams
Resume
HomeInterview PortalGit & GitHub
Branches β€’ Rebasing β€’ Merging
ALL HANDBOOKS
🎯LinuxπŸ™Git & GitHubπŸ€–GitHub Actions🌐Networking☁AWSπŸ› Terraform🐳Docker☸KubernetesπŸ”„GitOpsπŸ“ŠMonitoringπŸ›‘DevSecOpsβš™SREπŸ—System DesignπŸ’°Cost Optimization🚨Incident ScenariosπŸ‘€HR & Behavioral☁GCP🐍Python☁AWS Architect
πŸ™

Git & GitHub

// INTERVIEW & ARCHITECTURE HANDBOOK
Branches β€’ Rebasing β€’ Merging

Learn Git & GitHub core architecture, production scenario-based questions, incident response, and real-world engineering solutions.

πŸ™ Git & GitHub: Interactive Q&A Handbook#



🟒 1. Git Basics & Architecture#

❓ 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.

πŸ’‘ Reveal 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.

Why it is Used:#

  • Speed & Performance: Most operations are local, making them incredibly fast.
  • Distributed Architecture: Developers work offline and commit locally. A failure of the central server doesn't halt work or lose history.
  • Data Integrity: Git uses SHA-1 hashing to verify the integrity of every file and commit, making history modification virtually impossible without detection.
  • Branching & Merging: Highly efficient branching models allow developers to create isolated workspaces for features and merge them seamlessly.

❓ 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.

πŸ’‘ Reveal 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:

  • Enables Collaboration: Allows multiple engineers to branch off, develop features, and merge changes via Pull Requests (PRs).
  • Acts as the Source of Truth: Houses all infrastructure manifests (IaC) and application source code.
  • Powers Automation: Commits and merges act as automatic triggers for CI/CD pipeline builds.
  • Facilitates Safe Rollbacks: If a bug is deployed, reverting to a previous stable Git commit restores the system state.

❓ 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.

πŸ’‘ Reveal 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)                  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Working Directory (Workspace): The actual directory on your filesystem containing your project files. Here, files are in a modified but untracked/uncommitted state.
  2. Staging Area (Index): A prep area (index file) that stores information about what changes will be committed in the next snapshot. Files here are staged.
  3. Local Repository (commit history): The .git metadata database directory where Git stores committed snapshots of your project. Files here are committed.
  4. Remote Repository: A shared hosting server (like GitHub, GitLab, or Bitbucket) used to collaborate and sync history across teams.

❓ 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.

πŸ’‘ Reveal Technical Answer

Answer:

  • Git:
    • An open-source command-line tool and version control software installed locally on your machine.
    • Manages files, commits history, handles branches, and performs merges locally.
  • GitHub:
    • A cloud-based SaaS platform built around the Git tool.
    • Hosts Git repositories online, providing team access controls, graphical interfaces (GUIs), pull requests (PRs), code reviews, project boards, and automation tools (like GitHub Actions).

❓ Q4: What actually happens under the hood when we execute a 'git commit' command?#

Click on the dropdown below to reveal the technical answer.

πŸ’‘ Reveal Technical Answer

Answer: When you execute git commit -m "commit message", Git performs several actions behind the scenes:

  1. Gather Staged Files: Git looks at the staging area (index) to compile the snapshot.
  2. Create tree objects: Creates directory structure records mapping file names to their corresponding file hashes (blobs).
  3. Create a commit object: Writes a metadata file containing:
    • The hash of the root tree object.
    • The hash of the parent commit(s) (unless it is the initial commit).
    • Author and Committer names, emails, and timestamp.
    • The commit message.
  4. Generate SHA-1 hash: Generates a unique 40-character SHA-1 (or SHA-256) hash identifying this commit.
  5. Move HEAD pointer: Updates the pointer of the current active branch (and HEAD) to point to this new commit hash.

❓ 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.

πŸ’‘ Reveal 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:

  • Blob (Binary Large Object): Stores only the file contents (no metadata like file name, permissions, or directory paths).
  • Tree: Represents a directory. It contains directory listing rows mapping hashes to blobs (files) or other nested trees (subdirectories), along with file names and permissions.
  • Commit: Points to a single root tree object representing the repository state at that commit, lists parent commit hashes, and contains metadata (author, message, timestamp).
  • Tag: A reference pointing to a specific commit object, containing tag name, creator, and message.

🟑 2. Branching & Merging Strategies#

❓ 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.

πŸ’‘ Reveal Technical Answer

Answer: In Git, a branch is not a duplicate directory copy; it is simply a lightweight, mutable pointer to a specific commit.

How it works:#

  • When you create a branch, Git creates a new pointer file inside .git/refs/heads/ containing the 40-character SHA-1 hash of the commit you branched from.
  • As you make new commits, the branch pointer moves forward automatically to point to the latest commit.
  • This design makes branching and switching branches almost instantaneous, regardless of the size of the repository.

❓ 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.

πŸ’‘ Reveal Technical Answer

Answer: Both commands integrate changes from one branch into another, but they do it in fundamentally different ways:

  • git merge:
    • Combines the histories by executing a three-way merge and creating a new merge commit (if not fast-forward).
    • Pros: Preserves the complete, chronological history of what happened and when. Non-destructive.
    • Cons: Can result in a cluttered history graph with many overlapping merge lines.
  • git rebase:
    • Moves the entire base of the feature branch to begin at the tip of the target branch, effectively rewriting history. It plays back commits one-by-one onto the new base.
    • Pros: Results in a perfectly clean, linear history graph without unnecessary merge commits.
    • Cons: Rewrites history. Golden Rule of Rebasing: Never rebase branches that have been pushed to a public/shared repository, as it corrupts collaborators' local histories.
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.

πŸ’‘ Reveal 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.

Common Use Cases:#

  • Hotfixes: Porting a critical bug fix committed on a development branch directly to the production branch without merging the entire development history.
  • Undoing Commits: Applying a commit that was accidentally committed to the wrong branch onto the correct 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.

πŸ’‘ Reveal 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).

Why it is used:#

  • Keeps the destination branch's history clean by hiding internal development iterations, WIP commits, and formatting corrections from the main branch history.
  • Note: The source branch's detailed commit history is lost on the destination branch, but is still accessible in the Pull Request history on platforms like GitHub.

❓ 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.

πŸ’‘ Reveal 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.

How it works:#

  • Instead of creating a merge commit, Git simply moves the target branch pointer forward to point to the latest commit of the feature branch.
  • You can prevent this by running git merge --no-ff <branch>, which forces Git to create a merge commit, preserving the visual branch boundary in the history log.

πŸ”΄ 3. History Recovery & Undo Operations#

❓ 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.

πŸ’‘ Reveal Technical Answer

Answer: These commands are used to undo changes at different stages of the Git lifecycle:

  • git reset: Moves the branch pointer and HEAD to a specified commit. It is destructive if history was pushed.
    • --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.
  • git revert: Creates a brand new commit that applies the exact opposite changes of a target commit. It does not rewrite history, making it completely safe for shared/pushed branches.
  • git restore: Discards uncommitted changes in the Working Directory or Staging Area (e.g., restoring a modified file to match HEAD).

❓ 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.

πŸ’‘ Reveal 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.

Recovery Workflow:#

  1. Run git reflog to view the history of HEAD pointer updates. Find the SHA-1 hash of the commit before the reset/deletion occurred.
  2. Inspect the commit content using git show <commit-hash>.
  3. Recover the state:
    • Create a branch at that commit: git branch recovery-branch <commit-hash>.
    • Or reset current branch: 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.

πŸ’‘ Reveal 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.

πŸ’‘ Reveal 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.

How it happens:#

  • Running git checkout <commit-hash> instead of git checkout <branch-name>.

Implications:#

  • You can make commits in this state, but if you switch branches, those commits will not belong to any branch, making them "dangling" and eligible for garbage collection.
  • To save your work from a detached HEAD, create a branch immediately: 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.

πŸ’‘ Reveal Technical Answer

Answer: A deleted branch is simply a deleted pointer file. The underlying commits still exist.

Recovery Workflow:#

  1. Run git reflog and locate the hash of the latest commit on the branch before it was deleted (usually labeled checkout: moving from <branch> to ...).
  2. Recreate the branch pointing to that commit: git checkout -b <branch-name> <commit-hash>.

⚑ 4. Collaboration & Branching Models#

❓ Q16: What actually triggers a merge conflict in Git?#

Click on the dropdown below to reveal the technical answer.

πŸ’‘ Reveal 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.

πŸ’‘ Reveal Technical Answer

Answer: Resolving merge conflicts involves a structured process:

  1. Identify Conflicted Files: Git lists conflicted files. Run git status to view files marked both modified.
  2. Open Files & Inspect Conflict Markers: Locate the standard Git conflict markers in the source file:
    <<<<<<< HEAD
    Changes on the current active branch (e.g., main)
    =======
    Changes from the branch being merged in (e.g., feature)
    
  3. Edit Content: Manually edit the files to combine or select the desired changes, and remove all conflict markers.
  4. Stage Files: Stage the resolved files: git add <file-name>.
  5. Commit Resolution: Complete the merge operation: 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.

πŸ’‘ Reveal 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.

πŸ’‘ Reveal Technical Answer

Answer: GitHub Flow is a lightweight, agile branching model designed for continuous deployment environments.

Core Workflow:#

  1. Branch from main to create a descriptive feature branch (e.g., update-login-ui).
  2. Make commits locally and push to GitHub.
  3. Open a Pull Request (PR) to request feedback and trigger CI builds.
  4. Discuss, review code, and commit revisions.
  5. Merge the PR into 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.

πŸ’‘ Reveal 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.

Key Principles:#

  • Avoids long-lived feature branches to eliminate merge pain.
  • Feature branches are short-lived (usually less than a day).
  • Relies heavily on automated testing (CI) to prevent trunk breakage.
  • Uses Feature Flags (toggles) to merge incomplete features into production without exposing them to users.

LinuxBack to PortalGitHub Actions
On This Page
1. Git Basics & Architecture2. Branching & Merging Strategies3. History Recovery & Undo Operations4. Collaboration & Branching Models
APURV

Building scalable, secure, and production-ready cloud infrastructure. Automation first.

NAVIGATION

HomeExperienceProjectsCertificationsSkills

TECH STACK

AWSGCPK8sCI/CDLinuxDocker

CONNECT

LinkedInGitHubEmailResume

Β© 2026 Apurv Gujjar. All rights reserved.