Skip to content

Ambiguous Argument

Error message

                fatal: ambiguous argument 'x': both revision and filename
              

Quick summary

The name you provided matches both a branch/commit and a file — Git does not know which you mean.

Why this happens

  • A file and a branch share the same name

  • A file and a tag share the same name

  • A filename could be interpreted as a commit hash

Minimal example

✗ Broken code
git log main  # fatal: ambiguous argument 'main': both revision and filename
✓ Fixed code
# If you mean the branch:
git log refs/heads/main
# If you mean the file:
git log -- main

Use refs/heads/<name> for branches or -- <name> for files to disambiguate when names collide.

How to diagnose

  • Check if the name exists as both a file and a branch: ls <name> && git branch | grep <name>

  • Check if it is also a tag: git tag | grep <name>

How to fix

  • Use -- to separate paths from revisions: git log <name> -- (treats as file) or git log -- <name>

  • Use the full ref path: git log refs/heads/<name> for a branch

  • Rename the file or branch to avoid the collision

How to prevent

  • Avoid naming files the same as branches or tags

  • Use -- to disambiguate paths from revisions in commands

Related Resources

Related Glossary

Related Lessons

← Back to language