Bootstrap FreeKB - Git (Version Control) - Resolve "fatal: ambiguous argument: unknown revision or path not in the working tree
Git (Version Control) - Resolve "fatal: ambiguous argument: unknown revision or path not in the working tree

Updated:   |  Git (Version Control) articles

Let's say something like this is being returned.

fatal: ambiguous argument 'main...my-branch': unknown revision or path not in the working tree.

 

I got this when attempting to list the differences between the main branch and my-branch using the git diff command.

~]$ git diff --name-only main...my-branch
fatal: ambiguous argument 'main...my-branch': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

 

You should be able to replicate this by using the git clone command to clone your repo.

git clone git@github.com:acme/my-repo.git

 

And then move into the cloned repo directory.

cd my-repo/

 

And the git branch should show that main is the currently selected branch and my-branch is at remotes/origin.

]$ git branch --all
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/my-branch

 

Now issue the git diff command and the error should be returned.

~]$ git diff --name-only main...my-branch
fatal: ambiguous argument 'main...my-branch': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

 

The simple fix is to checkout my-branch.

]$ git checkout my-branch
branch 'my-branch' set up to track 'origin/my-branch'.
Switched to a new branch 'my-branch'

 

Now, my-branch will be a local branch in your clone of the repo.

~]$ git branch --all
* my-branch
  main
  remotes/origin/HEAD -> origin/main
  remotes/origin/my-branch

 

It shouldn't matter at this point if you remain on my-branch or if you swtich back to the main branch. The goal here was just to have a local clone of my-branch. The git diff command should now no longer return the stderr.

git diff --name-only main...my-branch

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter db984d in the box below so that we can be sure you are a human.