Skip to main content

Command System

Learn Git Branching provides an interactive command-line interface that simulates Git operations in a visual environment. The application supports multiple command types to help you learn and practice Git concepts.

Command Categories

The command system is organized into several categories:

Git Commands

Standard Git commands for version control operations

Mercurial Commands

Mercurial (hg) command support with Git translation

Special Commands

Learning-specific commands for levels and navigation

Command Processing

Commands go through a multi-stage processing pipeline:

1. Shortcut Expansion

Shortcuts are expanded first to their full command equivalents:
  • gcgit commit
  • gogit checkout
  • gbgit branch
  • grgit rebase
  • gst, gsgit status

2. Instant Commands

Some commands execute immediately without parsing:
  • git help - Display help information
  • show commands - List all available commands
  • show solution - Display the level solution
  • flip - Flip the tree visualization

3. Regular Parsing

Commands are parsed using regex patterns to:
  • Identify the command type (git, hg, sandbox, level)
  • Extract options and flags (e.g., --amend, -b)
  • Parse arguments and validate syntax

4. Command Execution

After parsing, commands are executed through:
  • Direct execution for Git/Mercurial operations
  • Delegation for commands that translate to other commands
  • Animation queue for visual updates

Command Format

All commands follow standard Unix command-line conventions:
<command> [options] [arguments]

Options

Options modify command behavior:
git commit --amend          # Long option
git branch -d feature       # Short option
git checkout -b new-branch  # Option with argument

Arguments

Arguments specify what to operate on:
git checkout main           # Branch name argument
git merge feature           # Branch to merge
git cherry-pick C1 C2 C3    # Multiple commit arguments

Golf Scoring

Some commands are excluded from “Golf Mode” scoring:
  • git status - Informational only
  • git log - Viewing history
  • git show - Inspecting commits
  • git add - Staging simulation
  • git rev-list - Internal use
These commands marked with dontCountForGolf: true don’t count toward your move count in levels.

Error Handling

The command system provides helpful error messages:
  • GitError - Git-specific errors (e.g., branch doesn’t exist)
  • CommandProcessError - Parsing or syntax errors
  • CommandResult - Informational messages
  • Warning - Non-fatal warnings

Command Reference Syntax

In this documentation:
  • <required> - Required argument
  • [optional] - Optional argument
  • | - Alternative options
  • ... - Can be repeated

Getting Help

Use these commands to learn more:
git help               # Show Git command help
help                   # General help
show commands          # List all commands with options
show solution          # See level solution

Next Steps

Git Commands

Learn all supported Git commands

Mercurial Commands

Use Mercurial instead of Git

Special Commands

Navigate levels and control the app

Build docs developers (and LLMs) love