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.How Git Golf Works
When you complete a level:- The system counts how many Git commands you used
- It compares your count to the optimal solution (best score)
- You receive feedback on your performance
Completing a Level
After solving a level, you’ll see a dialog showing:- Your score: 4 commands
- Optimal score: 3 commands
- Result: You can improve!
Matching the Best Score
When you match or beat the optimal 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: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 commitgit branchgit checkout/git switchgit mergegit rebasegit cherry-pickgit resetgit revertgit taggit pushgit pullgit fetch
Commands That Don’t Count
Utility and helper commands are excluded from scoring:show goal- Viewing the goal doesn’t countshow solution- Checking the answer doesn’t affect your scorehint- Getting help is free!objective- Reviewing instructionsundo- Undo is free (encourages experimentation)reset- Resetting the levelecho- Output commandsdelay- 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:- ✓ 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:2. Use Relative References
Relative refs can eliminate extra navigation: Instead of:3. Leverage Branch References
Use branch names instead of checking out first: Instead of:4. Combine with Semicolons
Chain commands together (though they still count individually):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
6. Study the Solutions
After completing a level, check the optimal solution:Example: Optimizing a Solution
Level Goal
Merge thefeature branch into main and delete feature.
First Attempt (4 commands)
Optimized Solution (3 commands)
Expert Solution (2 commands)
With careful positioning and using advanced techniques: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:- Navigate to the level:
- Try a more efficient solution
- Your best score is automatically saved
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:Git Golf Leaderboards
While Learn Git Branching doesn’t have built-in leaderboards, you can:Share Your Scores
Share your optimized solutions with others:- Create a permalink with your solution:
- Share the URL on social media, forums, or with friends
- Challenge others to beat your score!
Create Team Challenges
For teams and classrooms:- Pick a specific level
- Everyone attempts to solve it optimally
- Compare Git Golf scores
- Discuss different solution strategies
- Programming bootcamps
- University courses
- Team training sessions
- Git workshops
Command Efficiency Tips
Fast-Track Commands
| Inefficient | Efficient | Savings |
|---|---|---|
git branch xgit checkout x | git checkout -b x | 1 command |
git checkout C1git branch x | git branch x C1 | 1 command |
git checkout maingit merge feature | git merge feature (if already on main) | 1 command |
Multiple checkout for position | Use relative refs (^, ~) | Variable |
Relative Reference Mastery
Using^ and ~ effectively:
Branch Manipulation
Advanced Git Golf
Multi-Path Levels
Some levels have multiple optimal solutions with the same command count. For example: Solution A (3 commands):Remote Repository Levels
Remote levels add complexity to Git Golf: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:Pattern 2: Branch Pointer Manipulation
Goal: Move branch to specific commit Efficient:Pattern 3: Relative Navigation
Goal: Reference commits relative to current position Efficient:Git Golf Philosophy
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!