Skip to main content

Overview

Git Golf is a scoring system in Learn Git Branching that tracks how many commands you use to solve each level. Like golf, the goal is to achieve the lowest score possible - solving levels with fewer commands.
The name “Git Golf” plays on the golf scoring concept where lower scores are better. Can you match par?

How Git Golf Works

When you complete a level:
  1. The system counts how many Git commands you used
  2. It compares your count to the optimal solution (best score)
  3. You receive feedback on your performance

Completing a Level

After solving a level, you’ll see a dialog showing:
Great Job!!!

You solved the level in 4 command(s);
our solution uses 3.
This tells you:
  • Your score: 4 commands
  • Optimal score: 3 commands
  • Result: You can improve!

Matching the Best Score

When you match or beat the optimal solution:
Great Job!!!

You solved the level in 3 command(s);
our solution uses 3.

Awesome! You matched or exceeded our solution.
Matching the best score marks the level with a special indicator (⭐) in the levels menu.

Exceeding Par

If you used more commands than optimal:
You solved the level in 5 command(s);
our solution uses 3.

See if you can whittle it down to 3 :D
This encourages you to try again and optimize your solution!

Which Commands Count?

Git Golf only counts Git commands that modify the repository. Commands that don’t count include:

Commands That Count

All standard Git commands that change the repository state:
  • git commit
  • git branch
  • git checkout / git switch
  • git merge
  • git rebase
  • git cherry-pick
  • git reset
  • git revert
  • git tag
  • git push
  • git pull
  • git fetch
And many more…
If a command changes the commit tree visualization, it likely counts toward your Git Golf score.

Commands That Don’t Count

Utility and helper commands are excluded from scoring:
  • show goal - Viewing the goal doesn’t count
  • show solution - Checking the answer doesn’t affect your score
  • hint - Getting help is free!
  • objective - Reviewing instructions
  • undo - Undo is free (encourages experimentation)
  • reset - Resetting the level
  • echo - Output commands
  • delay - Timing commands
  • Navigation commands (levels, sandbox, etc.)
Errors don’t count! If a command fails, it won’t be added to your score. This encourages trying different approaches.

Viewing Your Scores

See your Git Golf scores in the levels menu:
levels
The levels dialog shows:
  • Checkmark - Level completed
  • Star/highlight - Best score achieved
  • Your command count vs. optimal solution

Strategies for Better Scores

1. Combine Operations

Use command options to do more in a single command: Instead of:
git branch feature
git checkout feature
Use:
git checkout -b feature
This reduces 2 commands to 1!

2. Use Relative References

Relative refs can eliminate extra navigation: Instead of:
git checkout C1
git checkout main
Use:
git checkout main^

3. Leverage Branch References

Use branch names instead of checking out first: Instead of:
git checkout feature
git merge main
Use (from main):
git merge feature

4. Combine with Semicolons

Chain commands together (though they still count individually):
git checkout -b feature;git commit;git checkout main;git merge feature
This doesn’t reduce your score, but helps execute complex solutions quickly.

5. Master Advanced Commands

Some advanced commands can replace multiple operations:
  • cherry-pick can grab commits without switching branches
  • rebase can move entire branch histories
  • reset can move branches without checking out
Example: Instead of (3 commands):
git checkout main
git checkout -b feature
git commit
Use (2 commands):
git branch feature main
git commit

6. Study the Solutions

After completing a level, check the optimal solution:
show solution
Even if you matched the best score, reviewing the solution can teach you elegant command patterns.

Example: Optimizing a Solution

Level Goal

Merge the feature branch into main and delete feature.

First Attempt (4 commands)

git checkout feature  # 1
git commit            # 2
git checkout main     # 3  
git merge feature     # 4
Score: 4 commands

Optimized Solution (3 commands)

git commit            # 1 (assuming we're already on feature)
git checkout main     # 2
git merge feature     # 3
Score: 3 commands By being already positioned on the correct branch, we eliminated one command!

Expert Solution (2 commands)

With careful positioning and using advanced techniques:
git commit            # 1 (on feature)
git rebase main       # 2 (rebase instead of merge to avoid checkout)
Score: 2 commands
Sometimes there are multiple solutions with the same optimal score. Git Golf measures efficiency, but there’s often more than one “correct” approach.

Competing with Yourself

Replay Levels

You can replay any level to improve your score:
  1. Navigate to the level:
level intro1  # or use the levels menu
  1. Try a more efficient solution
  2. Your best score is automatically saved
Your completion status is preserved, so replaying a level won’t “un-solve” it. Feel free to experiment!

Track Your Progress

The levels menu shows your improvement:
  • First completion: Marked as solved ✓
  • Optimal completion: Marked with best score ⭐
  • Overall progress: Count of levels solved optimally

Reset Your Progress

If you want to start fresh and re-solve all levels:
reset solved --confirm
This clears ALL your progress and Git Golf scores. Use with caution!

Git Golf Leaderboards

While Learn Git Branching doesn’t have built-in leaderboards, you can:

Share Your Scores

Share your optimized solutions with others:
  1. Create a permalink with your solution:
share permalink  
  1. Share the URL on social media, forums, or with friends
  2. Challenge others to beat your score!
See Sharing Permalinks for details.

Create Team Challenges

For teams and classrooms:
  1. Pick a specific level
  2. Everyone attempts to solve it optimally
  3. Compare Git Golf scores
  4. Discuss different solution strategies
This is great for:
  • Programming bootcamps
  • University courses
  • Team training sessions
  • Git workshops

Command Efficiency Tips

Fast-Track Commands

InefficientEfficientSavings
git branch x
git checkout x
git checkout -b x1 command
git checkout C1
git branch x
git branch x C11 command
git checkout main
git merge feature
git merge feature (if already on main)1 command
Multiple checkout for positionUse relative refs (^, ~)Variable

Relative Reference Mastery

Using ^ and ~ effectively:
# Instead of finding commit IDs
git checkout C4
git branch feature

# Use relatives
git branch feature HEAD~2

Branch Manipulation

# Move branch pointer without checking out
git branch -f main C6

# Instead of
git checkout main
git reset --hard C6

Advanced Git Golf

Multi-Path Levels

Some levels have multiple optimal solutions with the same command count. For example: Solution A (3 commands):
git checkout main
git merge feature
git branch -d feature
Solution B (3 commands):
git checkout feature  
git rebase main
git checkout main
Both achieve the goal in 3 commands but use different approaches!

Remote Repository Levels

Remote levels add complexity to Git Golf:
# Optimal push after diverged history
git fetch
git rebase o/main  
git push
Versus:
# Alternative approach
git pull --rebase
git push  
Both are 3 commands, but using git pull --rebase combines fetch+rebase!

Learning from Git Golf

Git Golf teaches valuable real-world skills:

1. Command Efficiency

Fewer commands mean:
  • Less typing in real projects
  • Faster workflows
  • Fewer opportunities for errors

2. Deep Command Knowledge

Pursuing optimal scores forces you to learn:
  • Command options and flags
  • Relative references
  • Advanced Git features

3. Problem-Solving Skills

Optimizing solutions requires:
  • Planning ahead
  • Understanding multiple solution paths
  • Creative thinking about Git operations

4. Real-World Habits

The patterns you learn through Git Golf apply directly to:
  • Daily development workflows
  • Complex Git operations
  • Team collaboration scenarios

Common Patterns

Pattern 1: Fast-Forward Merge Setup

Goal: Position branches for fast-forward merge Efficient:
git rebase main
Instead of:
git checkout main
git merge feature

Pattern 2: Branch Pointer Manipulation

Goal: Move branch to specific commit Efficient:
git branch -f main C4
Instead of:
git checkout main
git reset --hard C4  

Pattern 3: Relative Navigation

Goal: Reference commits relative to current position Efficient:
git checkout HEAD^2~3
Instead of:
git checkout C1
# ...multiple navigation commands

Git Golf Philosophy

Efficiency matters - In real projects, shorter command sequences mean faster workflows and fewer mistakes.
Multiple solutions exist - There’s rarely one “correct” answer. Git Golf encourages exploring different approaches.
Learn by optimizing - Trying to beat your score teaches Git concepts more deeply than just solving once.
Practice makes perfect - The more you optimize, the more these patterns become second nature.

Next Steps

  • Review all Levels and try to achieve best scores on each
  • Study efficient patterns in Sandbox Mode
  • Share your optimized solutions using Permalinks
  • Create efficiency challenges with Level Builder
  • Compete with friends to see who can achieve the most best scores!

Build docs developers (and LLMs) love