-1

I fork repo but the origin of the for has multiple branches and on my fork (web) I can see the the branches but when I try to switch branches on my computer I'm getting the following errors:

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

If I check if the branch exist:

git branch -a |grep myBranch01

I get:

  remotes/origin/myBranch01
  remotes/upstram/myBranch01
  remotes/upstream/myBranch01

any of you knows why I'm getting this error?, or what I'm doing wrong?

I'll really appreciate your help.

user2924482
  • 8,380
  • 23
  • 89
  • 173

1 Answers1

2

Git will automatically create a branch for you, if you don't have one yourself but you do have a corresponding remote-tracking branch (note that a remote-tracking branch is not a branch!).

The problem here is not that you don't have a corresponding remote-tracking branch. The problem is that you have too many corresponding remote-tracking branches.

You told Git to get on to, or create if necessary, myBranch01. There are three possible myBranch01 names it could use to create yours:

  • origin/myBranch01
  • upstram/myBranch01
  • upstream/myBranch01

The middle one is clearly due to a typo. But even if you delete the typo-ed remote, which takes away all those remote-tracking branches, you will still be left with two possible myBranch01 sources. Git won't know which one to use, so it will refuse to use either one.

The solution is to tell Git which one to use to create your branch. Once you have created your own branch, the other two remote-tracking branch names are much less important and it won't matter that there are two of them.

You can:

git checkout --track origin/myBranch01

to make your own myBranch01 from origin/myBranch01, or:

git checkout --track upstream/myBranch01

to make your own myBranch01 from upstream/myBranch01.

Which one of these you should use is a different question entirely (and one only you can answer).

torek
  • 448,244
  • 59
  • 642
  • 775
  • What is the difference between remotes/origin/myBranch01 and remotes/upstream/myBranch01 ? – user2924482 Jul 10 '17 at 21:56
  • " git checkout --track " it would create a new branch. Correct? – user2924482 Jul 10 '17 at 22:02
  • For your first question, I can only see the obvious difference: one is spelled with `origin` and one is spelled with `upstream`. Presumably this is because you have one remote named `origin` and another named `upstream` (plus the typo-ed one). For your second: yes, `git checkout --track ` is shorthand for `git checkout -b --track `, where Git computes the local branch name by taking off the obvious part from the remote-tracking branch name. – torek Jul 10 '17 at 22:09
  • on my case I don't want to create new branch I want to use the branches are already created – user2924482 Jul 10 '17 at 22:20
  • If you are going to make any commits yourself, you *must* make a new branch, otherwise you will not have any branches: remote-tracking branches are not branches! If you are just using a commit, you can use a "detached HEAD" and hence not use a branch. The choice is yours. – torek Jul 10 '17 at 22:25