error: pathspec 'test-branch' did not matc

2019-02-01 17:01发布

I am a new user of Git. I have forked a repository called Spoon-Knife (available for practicing forking with Git). Then, I cloned it locally by running

git clone https://github.com/rohinichoudhary/Spoon-Knife.git

This repository contains three branches, i.e.

  • master,
  • test-branch,
  • change-the-title.

When I run git branch, it only shows *master, not the remaining two branches. And when I run

git checkout test-branch

I get the following error:

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

Why is this happening? How can I solve this problem?

8条回答
我命由我不由天
2楼-- · 2019-02-01 17:37

Try cloning before doing the checkout.

do git clone "whee to find it" then after cloning check out the branch

查看更多
趁早两清
3楼-- · 2019-02-01 17:38

Solution:

To fix it you need to fetch first

$ git fetch origin

$ git rebase origin/master

Current branch master is up to date.

$ git checkout develop

Branch develop set up to track remote branch develop from origin.

Switched to a new branch ‘develop’

查看更多
【Aperson】
4楼-- · 2019-02-01 17:39

This error can also appear if your git branch is not correct even though case sensitive wise. In my case I was getting this error as actual branch name was "CORE-something" but I was taking pull like "core-something".

查看更多
不美不萌又怎样
5楼-- · 2019-02-01 17:51

You can also get this error with any version of git if the remote branch was created after your last clone/fetch and your local repo doesn't know about it yet. I solved it by doing a git fetch first which "tells" your local repo about all the remote branches.

git fetch
git checkout test-branch
查看更多
▲ chillily
6楼-- · 2019-02-01 17:56

The modern Git should able to detect remote branches and create a local one on checkout.

However if you did a shallow clone (e.g. with --depth 1), try the following commands to correct it:

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --all

and try to checkout out the branch again.

Alternatively try to unshallow your clone, e.g. git fetch --unshallow and try again.

See also: How to fetch all remote branches?

查看更多
趁早两清
7楼-- · 2019-02-01 17:57

just follow three steps, git branch problem will be solved.

git remote update
git fetch
git checkout --track origin/test-branch

查看更多
登录 后发表回答