GitHub
10 / 10

Advanced Git Workflows & Interview Questions

Advanced Git Workflows & Interview Questions

Branch Strategies

Git Flow (complex, suits release-heavy products):
  main        — production code
  develop     — integration branch
  feature/*   — feature branches off develop
  release/*   — stabilization before merge to main
  hotfix/*    — urgent fixes off main

GitHub Flow (simple, suits continuous deployment):
  main        — always deployable
  feature/*   — branch off main, PR back to main
  Deploys happen on merge to main

Trunk-Based Development (advanced, suits large teams):
  main (trunk) — everyone integrates frequently (at least daily)
  short-lived  — feature branches live < 2 days
  Feature flags — hide incomplete features behind flags
  Requires: strong CI, good test coverage, feature flags infrastructure

Merge Strategies — When to Use Which

  • Merge commit: preserves full history, shows exactly when branches diverged and merged. Good for release branches. Creates a merge commit.

  • Squash merge: combines all PR commits into one clean commit on main. Good for feature branches with messy WIP commits. Loses individual commit authorship.

  • Rebase merge: replays PR commits on top of main, linear history. Good when you want clean history without squashing. Rewrites commit SHAs.

  • Rule of thumb: squash for features, merge commit for release/hotfix, rebase for clean individual commits.

Undoing Things Safely

# Undo last commit — keep changes staged
git reset --soft HEAD~1

# Undo last commit — keep changes unstaged
git reset HEAD~1

# Undo last commit — discard changes (DESTRUCTIVE)
git reset --hard HEAD~1

# Undo a published commit (safe — creates new commit)
git revert abc123   # revert specific commit
git revert HEAD     # revert last commit

# Undo a file change
git checkout -- src/file.ts   # restore to last commit
git restore src/file.ts       # modern syntax

# Unstage a file
git restore --staged src/file.ts

# Fix last commit message (only before push!)
git commit --amend -m "Correct message"

# Add forgotten file to last commit (before push)
git add forgotten-file.ts
git commit --amend --no-edit

Cherry-Pick & Interactive Rebase

# Apply specific commits to current branch
git cherry-pick abc123
git cherry-pick abc123..def456   # range

# Interactive rebase — rewrite history (before push only)
git rebase -i HEAD~5    # last 5 commits

# Commands in interactive rebase:
# pick    — keep commit as-is
# reword  — keep but edit message
# edit    — stop and allow amending
# squash  — combine with previous commit
# fixup   — like squash but discard this commit's message
# drop    — remove commit entirely

Interview Questions

  • Git Flow vs GitHub Flow? Git Flow: complex, good for versioned releases (libraries, mobile apps). GitHub Flow: simple, good for web apps with continuous deployment. Trunk-Based: advanced, suits large teams with feature flags.

  • Squash vs rebase vs merge commit? Squash: one clean commit, lose individual history. Rebase: linear history, rewrites SHAs (risky if shared). Merge: preserves history, creates merge commit. Choose based on team conventions and whether the branch is shared.

  • How to undo a published commit? git revert — creates a new commit that undoes the changes. Never git reset --hard on published branches (rewrites shared history).

  • Monorepo vs polyrepo? Monorepo: shared CI, easy refactors across packages, atomic cross-package changes, but slower CI and more tooling complexity. Polyrepo: independent deployment, isolated concerns, but cross-repo changes are hard and dependency management is complex.

  • CODEOWNERS purpose? Automatically assigns reviewers based on file paths. Ensures domain experts review relevant changes. Enforced via branch protection (require CODEOWNER review).

  • How does GitHub Actions caching work? Cache key is a hash. On hit: restore. On miss: run steps, then save cache at end. Keys support restore-keys for fallback. Cache is scoped to branch + OS. Max 10GB per repo.

  • What is a protected branch? Branch with rules preventing direct pushes, requiring PR reviews, passing CI, and/or CODEOWNER approval before merge. Prevents accidental or unauthorized changes to main.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free