git checkout 分支名不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31267019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git checkout branchname is not working
提问by OneTwo
I have created new project into stash repository and also i have created few branches in stash for this new project. I am able to clone the project from git bash but when i try to checkout particular branch i was getting below error
我已经在 stash 存储库中创建了新项目,并且我还在 stash 中为这个新项目创建了几个分支。我可以从 git bash 克隆项目,但是当我尝试结帐特定分支时,出现以下错误
git checkout feature/Project_branch
error: pathspec 'feature/Project_branch' did not match any file(s) known to git.
but if i use as below then its working
但如果我使用如下,那么它的工作
git fetch origin
git checkout feature/Project_branch
There are other projects which i used to checkout it was working without using git fetch origin command
, but in my new repository case its throwing above error.
还有其他项目,我曾经在没有使用的git fetch origin command
情况下检出它正在工作,但在我的新存储库案例中,它抛出了上述错误。
Can any one please help me to unsderstand, is there any configuration i have to do to directly checkout the branch with git checkout
without using git fetch
command?
任何人都可以帮助我理解,我需要做任何配置才能直接结帐分支git checkout
而不使用git fetch
命令吗?
采纳答案by JDrost1818
All git fetch
does is download information into your repository that you don't already have. This means that when you were first trying to switch to feature/Project_branch, you hadn't downloaded it yet. You can get it in two ways
所有git fetch
所做的就是下载信息到你的仓库,你还没有。这意味着当您第一次尝试切换到 feature/Project_branch 时,您还没有下载它。您可以通过两种方式获得
1 - Upon the original git clone
, all branches currently associated with the remote repository will be downloaded and made usable on your local git repo.
1 - 在原始版本上git clone
,当前与远程存储库关联的所有分支都将被下载并在您的本地 git 存储库上可用。
2 - If a new branch is added to the remote repository after your git clone
, you must perform a git fetch
, or a similar action such as git pull
, in order to gain access to the branch.
2 - 如果在您的 之后将新分支添加到远程存储库git clone
,则必须执行git fetch
或类似操作,例如git pull
,以获得对该分支的访问权限。
What must have happened is that the branch you wanted to switch to was not created and pushed when you originally cloned the repository, that is why you had to do a git fetch
一定发生的事情是,当您最初克隆存储库时,您想要切换到的分支并未创建和推送,这就是为什么您必须执行 git fetch
However, from now on, you should not have to run git fetch
in order to switch between master and feature/Project_branch.
但是,从现在开始,您不必git fetch
为了在 master 和 feature/Project_branch 之间切换而运行。
Note:
git branch
will list all branches you have at your disposal in your local repo.
注意:
git branch
将列出您在本地存储库中可以使用的所有分支。
回答by TheGeorgeous
I think you are missing the -t
option in checkout.
我认为您缺少-t
结帐时的选项。
Try this instead:
试试这个:
$ git checkout -t feature/Project_branch
This will create a branch called Project_branch
that is tracking feature/Project_branch
这将创建一个名为Project_branch
跟踪的分支feature/Project_branch