Skip to main content
The Advanced Topics sequence presents challenging Git scenarios that will test your understanding of rebasing, branch manipulation, and commit tree navigation. These levels require combining multiple techniques you’ve learned.

Overview

This sequence contains complex puzzles that simulate real-world Git scenarios. You’ll need to use rebase, relative refs, branch manipulation, and strategic thinking to solve these challenges.
These levels are genuinely difficult! Don’t be discouraged if they take multiple attempts. The goal is to make you think deeply about how Git works.

Levels in This Sequence

1. Multiple Rebases

What you’ll learn: How to perform multiple rebase operations in sequence. Key concepts:
  • Sometimes one rebase isn’t enough
  • You may need to rebase multiple branches in a specific order
  • Each rebase changes the commit tree
  • Planning the sequence matters
  • Understanding parent-child relationships is crucial
Challenge: Given a complex branching structure, rebase multiple branches to achieve a linear history. Skills required:
  • Understanding rebase mechanics
  • Visualizing the commit tree
  • Planning multi-step operations
  • Using relative refs
Example approach:
# Step 1: Rebase feature onto main
git checkout feature
git rebase main

# Step 2: Rebase bugfix onto updated feature
git checkout bugfix  
git rebase feature

# Step 3: Update main
git checkout main
git rebase bugfix
Draw out the commit tree on paper before attempting complex multi-rebase scenarios. Plan your moves!

2. Multiple Parents (Branch Spaghetti)

What you’ll learn: How to navigate and work with merge commits that have multiple parents. Key concepts:
  • Merge commits have two parent commits
  • ^ with a number specifies which parent: ^1, ^2
  • ^ without a number defaults to first parent
  • Can combine with ~: HEAD~^2~2
  • Understanding parent numbering is key to navigating complex trees
Challenge: Navigate to specific commits in a tree with multiple merge commits. Advanced relative refs:
HEAD^      # First parent of HEAD
HEAD^2     # Second parent of HEAD (from merged branch)
HEAD~2     # Two commits back following first parents
HEAD~^2    # Second parent of grandparent
HEAD~^2~3  # Complex navigation through merge commits
Example scenario:
# Navigate through merge commit parents
git checkout main^2      # Go to second parent of main
git branch -f bugFix HEAD~^2~3  # Complex parent navigation
Merge commits can be confusing. Remember: ^ chooses between parents, ~ goes back generations.

3. Selective Rebase

What you’ll learn: How to selectively choose which commits to include when rebasing. Key concepts:
  • Not all commits need to be rebased
  • Use interactive rebase to omit commits
  • Cherry-pick can select specific commits
  • Combining multiple techniques achieves precise control
  • Sometimes you want to exclude certain commits
Challenge: Rebase a branch but exclude specific commits from the operation. Approaches: Approach 1: Interactive Rebase
git rebase -i main
# In the dialog, delete lines for commits you don't want
Approach 2: Cherry-pick Strategy
# Manually cherry-pick only the commits you want
git checkout main
git cherry-pick C2
git cherry-pick C4  
git cherry-pick C5
# (omitting C3)
Approach 3: Rebase with Exclusion
# Rebase but drop specific commits
git rebase -i HEAD~5
# Mark unwanted commits as 'drop' or delete those lines

Problem-Solving Strategies

Advanced Git problems require systematic thinking:

Strategy 1: Work Backwards

Look at the goal state and work backwards to your current state:
  1. Where do we need to end up?
  2. What’s different from current state?
  3. What operations would create those differences?
  4. In what order should we apply them?

Strategy 2: Break Into Steps

Complex problems are easier when broken down:
  1. Identify independent sub-problems
  2. Solve each sub-problem separately
  3. Combine solutions in correct order
  4. Verify the result matches the goal

Strategy 3: Use the Sandbox

Learn Git Branching lets you experiment:
  1. Try an approach
  2. If it doesn’t work, use undo or reset
  3. Try a different approach
  4. Learn from each attempt
Use the show solution feature if you’re truly stuck, but try to understand WHY the solution works.

Common Advanced Patterns

Pattern 1: Rebase Multiple Branches

# Scenario: Multiple feature branches need to stack
git checkout feature1
git rebase main

git checkout feature2
git rebase feature1

git checkout feature3
git rebase feature2

Pattern 2: Navigate Complex Merges

# Find specific commits in merge history
git checkout main^2^    # Second parent's parent
git checkout HEAD~^2    # Grandparent's second parent

Pattern 3: Selective History Rewriting

# Keep some commits, discard others
git rebase -i HEAD~10
# Reorder, omit, or squash commits as needed

Advanced Concepts Summary

ConceptSyntaxDescription
Multiple rebasesSequential git rebaseStack multiple rebase operations
Parent selection^1, ^2Choose which parent of merge commit
Combined refs~^2~3Navigate complex merge histories
Selective rebasegit rebase -iChoose which commits to include
Strategic planningThink before executing commands

Tips for Success

Visualize First: Always understand the current tree structure before making changes.
Plan Multiple Steps: Advanced problems often require 3-5 commands in sequence. Plan them all first.
Test Incrementally: Execute one command at a time and verify it did what you expected.
Don’t Rush: These levels are designed to be challenging. Take your time and think through each step.

What’s Next?

After conquering the Advanced Topics sequence:
  • Remote Repositories: Apply your skills to collaborative workflows
  • Remote Advanced: Face even more complex scenarios with remote branches
  • Practice Mode: Review any sequence to reinforce your skills

Challenge Yourself

Take on the Advanced Topics sequence

Additional Resources

  • Review the Introduction Sequence if rebase concepts feel shaky
  • Revisit Ramping Up for relative refs practice
  • Check out Mixed Bag for interactive rebase techniques

Build docs developers (and LLMs) love