Skip to main content
The Ramping Up sequence builds on the fundamentals from the Introduction Sequence. Here you’ll learn advanced navigation techniques and powerful commands for manipulating commit history.

Overview

This sequence introduces you to Git’s powerful features for navigating and modifying your commit tree. You’ll learn how to reference commits relatively, understand detached HEAD state, and selectively move commits around.

Levels in This Sequence

1. Detach yo’ HEAD

What you’ll learn: How HEAD works and what “detached HEAD” means. Key concepts:
  • HEAD is the symbolic name for the currently checked out commit
  • HEAD usually points to a branch name (like main)
  • When you commit, the branch HEAD points to moves forward
  • You can checkout specific commits directly, creating a “detached HEAD”
  • In detached HEAD state, you’re working directly on a commit, not a branch
Goal: Check out a specific commit by its hash to enter detached HEAD state. Commands introduced:
git checkout <commit-hash>  # Checkout a specific commit
Example:
git checkout C4  # HEAD now points directly to C4, not a branch
In the visualization, commits have labels like C1, C2, etc. In real Git, you’d use commit hashes like fed2da64c0efc5293610bdd892f82a58e8cbc5d8.

2. Relative Refs

What you’ll learn: How to reference commits relative to branches and HEAD. Key concepts:
  • ^ moves up one commit in the tree (to the parent)
  • ~<num> moves up multiple commits
  • You can chain these operators: main^^ or HEAD~3
  • Relative refs work with any branch or HEAD
  • These make navigating the commit tree much easier
Goal: Use relative refs to navigate to specific commits. Commands introduced:
git checkout main^   # One commit above main
git checkout HEAD~3  # Three commits above current position
Examples:
git checkout main^      # Parent of main
git checkout main^^     # Grandparent of main  
git checkout HEAD~4     # Four commits back from HEAD
git checkout bugFix~2   # Two commits back from bugFix

3. Relative Refs #2

What you’ll learn: How to move branches using relative references. Key concepts:
  • Branch names are just pointers that can be reassigned
  • -f flag forces a branch to move to a new location
  • You can use relative refs to specify where to move branches
  • This is useful for correcting mistakes or reorganizing branches
Commands introduced:
git branch -f <branch> <location>  # Force branch to new location
Examples:
git branch -f main HEAD~3    # Move main to 3 commits back
git branch -f bugFix C2      # Move bugFix to commit C2
git branch -f main main~1    # Move main back one commit
Be careful with git branch -f on branches that others are using. This rewrites history and can cause problems for collaborators.

4. Reversing Changes

What you’ll learn: How to undo commits using reset and revert. Key concepts:
  • git reset moves the branch backwards, erasing commits (locally)
  • git revert creates a new commit that undoes changes (safe for shared branches)
  • Reset is like “rewriting history” - use it for local work only
  • Revert preserves history and is safe for shared branches
  • Both accomplish undoing changes, but in different ways
Commands introduced:
git reset <location>   # Move branch backward, erasing commits
git revert <location>  # Create new commit that undoes changes
Examples:
# Local branch - use reset
git reset HEAD~1       # Undo last commit locally

# Shared branch - use revert  
git revert HEAD        # Create commit that undoes HEAD
Use git reset for local branches and git revert for shared/remote branches. Reset rewrites history; revert preserves it.

Moving Work Around (Bonus Levels)

The following levels are part of the broader “ramping up” experience:

Cherry-pick

What you’ll learn: How to copy specific commits to your current location. Key concepts:
  • Cherry-pick copies commits to wherever HEAD is
  • You specify which commits you want
  • Great for when you know exactly which commits you need
Commands introduced:
git cherry-pick <commit1> <commit2> ...  # Copy specific commits
Example:
git cherry-pick C2 C4  # Copy commits C2 and C4 to current HEAD

Interactive Rebase

What you’ll learn: How to use an interactive UI to reorder, omit, or squash commits. Key concepts:
  • Interactive rebase opens a dialog to rearrange commits
  • You can reorder commits, omit them, or combine them
  • Great when you don’t know commit hashes but want to reorganize
  • More powerful than regular cherry-pick
Commands introduced:
git rebase -i <location>  # Interactive rebase
Example:
git rebase -i HEAD~4  # Interactive rebase for last 4 commits
In the Learn Git Branching tool, the interactive UI shows commits you can reorder or omit with a visual interface.

Key Techniques Summary

TechniqueCommandUse When
Relative Movement^, ~Navigating commit tree
Force Branchgit branch -fMoving branches to specific commits
Resetgit resetUndoing local commits
Revertgit revertUndoing commits on shared branches
Cherry-pickgit cherry-pickCopying specific commits
Interactive Rebasegit rebase -iReorganizing multiple commits

What’s Next?

After mastering the Ramping Up sequence, you’ll be ready for:
  • A Mixed Bag: Git techniques, tricks, and tips for various scenarios
  • Advanced Topics: Challenge yourself with complex rebasing scenarios
  • Remote Repositories: Learn to collaborate with git remotes

Continue Learning

Progress to the next sequence in the interactive tutorial

Build docs developers (and LLMs) love