01 / 01

A simple solution to a tricky command-line problem

git's --end-of-options Flag

From Hacker News

132 points

02

The Problem

When branch names collide with command options

The Ambiguity Dilemma

  • 01
    Branch names starting with dashes Names like '-new-feature' confuse git's option parser
  • 02
    Git interprets them as flags Instead of treating '-new-feature' as a branch name
  • 03
    Unexpected behavior or errors Commands fail or behave unpredictably
  • 04
    Common in fast-paced workflows Developers often use shorthand naming conventions

Workarounds vs Proper Solution

Using --
  • Standard git convention
  • Signals end of options
  • Works but requires knowledge
  • Can be forgotten easily
Path prefix ./
  • Specify path explicitly
  • git checkout ./-file
  • Only works for files
  • Not applicable to branches
--end-of-options Recommended
  • Explicit and readable
  • Self-documenting code
  • Clearer intent in scripts
  • Modern git standard
05

How It Works

Practical implementation examples

Real-World Examples

terminal
# Traditional approach with --
git checkout -- -new-feature

# New explicit approach
git checkout --end-of-options -new-feature

# Useful in scripts for clarity
git log --end-of-options --some-branch

The --end-of-options flag clearly separates options from arguments

Why It Matters

Clear advantages for developers and teams

visibility

Readability

Self-documenting commands that clearly express intent

shield

Safety

Prevents accidental option interpretation errors

code

Script Friendly

Ideal for automation and CI/CD pipelines

settings_suggest

Backwards Compatible

Works alongside existing -- convention

Thank You

Clearer git commands, fewer surprises

Source: Hacker News • nesbitt.io
Made with AirSlide
𝕏 in