Git Advanced Workflows - Complete Interview Guide

Learn advanced Git workflows including branching strategies, rebasing, cherry-picking, stashing, Git internals, merge strategies, conflict resolution, hooks, submodules, and enterprise Git best practices.

Introduction

Once you're comfortable with Git fundamentals, the next step is learning how Git is used in real-world enterprise development. Large organizations with hundreds of developers rely on advanced Git workflows to manage parallel development, code reviews, releases, hotfixes, and production deployments.

This guide introduces the most important advanced Git concepts every software engineer should know for enterprise projects and technical interviews.


Learning Objectives

After completing this chapter, you will understand:

  • Git Internals
  • Branching Strategies
  • Merge Strategies
  • Git Rebase
  • Cherry-pick
  • Git Stash
  • Reset vs Restore vs Revert
  • Git Reflog
  • Git Hooks
  • Git Submodules
  • Git Subtree
  • Git LFS
  • Conflict Resolution
  • Enterprise Git Workflow
  • Release Management
  • Git Best Practices

Why Advanced Git?

As projects grow, teams need efficient ways to:

  • Develop multiple features simultaneously
  • Fix production bugs
  • Release software safely
  • Collaborate across teams
  • Maintain clean commit history
  • Automate quality checks
  • Recover from mistakes

Git Internals

Understanding Git internals helps developers troubleshoot issues and appreciate Git's performance.

Topics:

  • Git Objects
  • Blob
  • Tree
  • Commit Object
  • Tag Object
  • SHA-1 Hash
  • References (Refs)
  • HEAD
  • Detached HEAD
  • Object Database
  • Index File

Git Object Model

Working Directory
        │
        ▼
Staging Area (Index)
        │
        ▼
Commit Object
        │
        ▼
Blob Objects
        │
        ▼
Tree Objects

Branching Strategies

Enterprise teams use different branching models depending on release frequency and team size.

Topics:

  • Feature Branch Workflow
  • Git Flow
  • GitHub Flow
  • GitLab Flow
  • Trunk-Based Development
  • Release Branches
  • Hotfix Branches
  • Long-lived Branches
  • Short-lived Branches

Git Flow

main
 │
 ├──────────────┐
 │              │
develop         │
 │              │
 ├──Feature A   │
 ├──Feature B   │
 └──Feature C   │
 │
Release Branch
 │
Hotfix Branch
 │
main

Suitable for large enterprise applications with scheduled releases.


GitHub Flow

main
 │
Feature Branch
 │
Pull Request
 │
Code Review
 │
Merge
 │
Deploy

Ideal for continuous delivery and cloud-native applications.


Trunk-Based Development

main
 │
 ├──Small Commit
 ├──Small Commit
 ├──Small Commit
 └──Deploy

Recommended for DevOps and CI/CD environments.


Merge Strategies

Git supports multiple merge strategies.

Topics:

  • Fast Forward Merge
  • Three-way Merge
  • Recursive Merge
  • Squash Merge
  • Octopus Merge

Merge vs Rebase

Merge

Feature
     \
      \
main ---- Merge Commit

Rebase

main
  │
Feature commits replayed
  │
Updated Feature Branch

Use Merge to preserve history.

Use Rebase for a cleaner commit history.


Interactive Rebase

Topics:

  • Edit Commits
  • Reorder Commits
  • Squash Commits
  • Drop Commits
  • Rewrite Commit Messages

Cherry-pick

Cherry-pick copies specific commits from one branch to another.

Common use cases:

  • Production Hotfix
  • Bug Fix Migration
  • Selective Feature Migration

Git Stash

Git Stash temporarily saves uncommitted changes.

Topics:

  • Stash
  • Apply
  • Pop
  • Drop
  • Named Stashes
  • Multiple Stashes

Useful when switching branches without committing unfinished work.


Reset vs Restore vs Revert

Git Reset

Moves branch pointer.

Types:

  • Soft
  • Mixed
  • Hard

Git Restore

Restores working directory files without affecting commit history.


Git Revert

Creates a new commit that reverses previous changes.

Safe for shared branches.


Git Reflog

Git Reflog records every movement of HEAD.

Useful for:

  • Recovering deleted commits
  • Restoring deleted branches
  • Undoing accidental resets

Detached HEAD

Occurs when HEAD points directly to a commit instead of a branch.

Topics:

  • Causes
  • Risks
  • Recovery
  • Best Practices

Merge Conflicts

Conflicts occur when Git cannot automatically combine changes.

Common reasons:

  • Same line modified
  • Deleted vs modified file
  • File rename conflicts

Conflict Resolution Steps:

  1. Identify conflict
  2. Edit conflicting file
  3. Test changes
  4. Stage changes
  5. Commit merge

Git Hooks

Git Hooks automate tasks during Git operations.

Common hooks:

  • pre-commit
  • commit-msg
  • pre-push
  • post-merge
  • pre-receive
  • post-checkout

Typical uses:

  • Code formatting
  • Unit testing
  • Static analysis
  • Secret scanning

Git Submodules

Submodules allow one Git repository to reference another repository.

Use cases:

  • Shared libraries
  • Common utilities
  • Third-party code

Advantages:

  • Independent versioning
  • Reusable components

Limitations:

  • Additional management complexity
  • Separate update process

Git Subtree

Git Subtree embeds another repository into the current repository.

Advantages:

  • Simpler than submodules
  • Easier cloning
  • No separate initialization

Git Large File Storage (Git LFS)

Git LFS manages large binary files outside the normal Git object database.

Common file types:

  • Images
  • Videos
  • Machine Learning Models
  • Large ZIP Files
  • Design Assets

Release Management

Topics:

  • Semantic Versioning
  • Release Tags
  • Release Branches
  • Hotfix Releases
  • Production Deployment Tags

Example:

v1.0.0

v1.1.0

v2.0.0

Pull Requests

Pull Requests enable collaborative development.

Typical workflow:

Feature Branch
      │
Push
      │
Pull Request
      │
Code Review
      │
CI Pipeline
      │
Approval
      │
Merge

Code Reviews

Best practices:

  • Small Pull Requests
  • Clear descriptions
  • Automated testing
  • Meaningful comments
  • Approval before merge

Enterprise Git Workflow

Developer

     │

Feature Branch

     │

Commit

     │

Push

     │

Pull Request

     │

Code Review

     │

CI Pipeline

     │

Merge

     │

CD Pipeline

     │

Production

Git Security

Topics:

  • Signed Commits
  • Protected Branches
  • Branch Permissions
  • Secret Scanning
  • Commit Verification
  • Repository Access Control

Repository Maintenance

Topics:

  • Garbage Collection
  • git gc
  • Repository Cleanup
  • git prune
  • Repository Integrity
  • git fsck

Common Enterprise Scenarios

  • Long-running feature branches
  • Multiple release versions
  • Production hotfixes
  • Emergency rollback
  • Cherry-picking fixes
  • Resolving merge conflicts
  • Recovering deleted commits
  • Recovering deleted branches
  • Rewriting commit history
  • Large team collaboration

Advanced Git Commands

Command Purpose
git rebase Reapply commits on another base
git cherry-pick Copy selected commits
git stash Temporarily save changes
git reflog View HEAD history
git reset Move branch pointer
git restore Restore files
git revert Reverse a commit
git merge --squash Squash commits
git worktree Multiple working directories
git bisect Find bug-causing commit
git gc Repository cleanup
git fsck Repository integrity check
git submodule Manage submodules
git subtree Manage subtrees

Best Practices

  • Keep feature branches short-lived.
  • Prefer Pull Requests for code reviews.
  • Never force-push to shared branches.
  • Rebase feature branches before merging when appropriate.
  • Use semantic version tags for releases.
  • Resolve conflicts promptly.
  • Protect the main branch.
  • Automate testing with Git hooks or CI pipelines.
  • Keep commit history clean and meaningful.
  • Tag every production release.

Interview Summary

After completing this chapter, you should understand:

  • Git Internals
  • Git Objects
  • Branching Strategies
  • Git Flow
  • GitHub Flow
  • Trunk-Based Development
  • Merge Strategies
  • Rebase
  • Cherry-pick
  • Git Stash
  • Reset
  • Restore
  • Revert
  • Reflog
  • Detached HEAD
  • Merge Conflicts
  • Git Hooks
  • Git Submodules
  • Git Subtree
  • Git LFS
  • Pull Requests
  • Release Management
  • Enterprise Git Workflow
  • Git Security
  • Repository Maintenance