GIT: Fatal Ambiguous Argument, Branch and Filename

03-26-2021

While rare, you might run into an error when using Git version control that your branch name and a filename are the same. The error happens when you attempt to run a git command using the conflicting name.

Error:

fatal: ambiguous argument ‘branch_name’: both revision and filename

As an example, we’ll try to run the git log command. We receive an error when we have a branch named _branch_name_ AND a file named _branch_name_ (why would you do that 🤔).

To treat _branch_name_ as a branch:

1
git log --oneline branch_name --

To treat the _branch_name_ as a file:

1
git log --oneline -- branch_name

Credit to this StackOverflow poster.