1

I am trying to checkout remote branch, but it fails with

error: pathspec 'branchName' did not match any file(s) known to git.

Git branch -a shows only the local branches and master branch but not other remote branches.

I think this is config problem but not able to sort out. Help!

Edit 1:

git remote show origin

fails with

fatal: Invalid refspec '....'

Can anyone provide a standard content for this in .git/config file?

Gaurav Aradhye
  • 334
  • 3
  • 14
  • possible duplicate of [Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git](http://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn) – Jauch Nov 28 '14 at 10:00
  • Possible duplicate of [GIT isn't fetching my new branch](http://stackoverflow.com/questions/28663933/git-isnt-fetching-my-new-branch) – kenorb Oct 11 '16 at 20:56

2 Answers2

5

As I had guessed, the problem was with the config. Git Fetch was not helping.

My config had the remote origin content as

[remote "origin"]
    fetch = +refs/heads/:refs/remotes/origin/
    url = "git repo url"

But it is important to append * next to the origin/ and heads/

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = "git repo url"
Gaurav Aradhye
  • 334
  • 3
  • 14
  • Good you found the problem. I'm curious about what caused this configuration problem... – Jauch Nov 28 '14 at 14:12
  • I am not sure too... May be this was unintended change that got in while I was making other config changes months back. – Gaurav Aradhye Nov 30 '14 at 22:06
  • thank you! just spent the past half hour trying to find out what the problem was until I finally stumbled onto this! – sblaks Aug 26 '20 at 18:53
1

You can take a look here: Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git

Probably you need to "git fetch" before checkout (your local repository seems to not know about the remote).

Community
  • 1
  • 1
Jauch
  • 1,500
  • 9
  • 19