2

I've found an interesting scenario. This question is related to this one.

I have git (version 1.8.3.1) and I created a branch locally, then I pushed it to my remote repository. I checked (git branch -a) that it exists on the remote repository.

Now, I have the repository setup on another machine. When I run the following commands (using the version 1.8.3.1):

git fetch git checkout <my branch> 

I checkout to my branch correctly.

However, I also have the git version git version 2.6.3. And when I run the above commands, I get the error:

error: pathspec '<branch name>' did not match any file(s) known to git. 

I'd expect this error in case of an older git version (see the linked question), but why does it fail for the version 2.6.3?

If I checkout to my branch using the older version of git, I can also checkout it using the git version 2.6.3.

Does it mean that git developers decided to remove this nice functionality introduced in v1.7.0-rc0 and I have to run git checkout -b <branch> --track <remote>/<branch> or am I making a mistake somewhere?

4
  • Try git fetch origin <branch>:refs/remotes/origin/<branch> && git checkout <branch>. Your git fetch doesn't get anything. Besides, you need to make sure that origin exists. If it does not, run git remote add origin <url> first. origin can be another name and replace orign in refs/remotes/origin/<branch> with the other name if it has already been there. Commented Oct 11, 2017 at 13:28
  • Add the output of git branch -r to your question. I think I know the answer, but will need to refer to it. Commented Oct 11, 2017 at 17:03
  • You can use git branch -a to check if the branch name is exist on remote. If exists, then copy (not input) the branch name after git checkout. Such as if the branch name is –a, there usually cause typos since –a is different from -a. So you'd better copy the branch name. Commented Oct 12, 2017 at 1:44
  • Has the problem been solved? Commented Oct 24, 2017 at 8:35

1 Answer 1

2

If origin/mybranch does exist, a simple

git checkout mybranch 

should be enough.

So double check what git branch -r shows you after a git fetch.

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

$ git checkout -b <branch> --track <remote>/<branch> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.