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?
git fetch origin <branch>:refs/remotes/origin/<branch> && git checkout <branch>. Yourgit fetchdoesn't get anything. Besides, you need to make sure thatoriginexists. If it does not, rungit remote add origin <url>first.origincan be another name and replaceorigninrefs/remotes/origin/<branch>with the other name if it has already been there.git branch -rto your question. I think I know the answer, but will need to refer to it.git branch -ato check if the branch name is exist on remote. If exists, then copy (not input) the branch name aftergit checkout. Such as if the branch name is–a, there usually cause typos since–ais different from-a. So you'd better copy the branch name.