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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:10:54  来源:igfitidea点击:

git checkout branchname is not working

gitgithubgit-stash

提问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 checkoutwithout using git fetchcommand?

任何人都可以帮助我理解,我需要做任何配置才能直接结帐分支git checkout而不使用git fetch命令吗?

采纳答案by JDrost1818

All git fetchdoes 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 fetchin order to switch between master and feature/Project_branch.

但是,从现在开始,您不必git fetch为了在 master 和 feature/Project_branch 之间切换而运行。

Note: git branchwill list all branches you have at your disposal in your local repo.

注意: git branch将列出您在本地存储库中可以使用的所有分支。

回答by TheGeorgeous

I think you are missing the -toption in checkout.

我认为您缺少-t结帐时的选项。

Try this instead:

试试这个:

$ git checkout -t feature/Project_branch

This will create a branch called Project_branchthat is tracking feature/Project_branch

这将创建一个名为Project_branch跟踪的分支feature/Project_branch