为什么git checkout< remote_branchname>不创建新的跟踪分支? [英] Why does git checkout <remote_branchname> not create new tracking branch?

查看:689
本文介绍了为什么git checkout< remote_branchname>不创建新的跟踪分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR :如果X作为远程分支存在,那么 git checkout X 应该创建它的本地分支。在我的情况下,对于单个分支,它不会。



远程存储库有一个 master, release,和其他一些分支(比如 refactor-update
我是这样做的:



git clone WHATEVER / repo.git


git checkout release

但我没有得到正常的分支切换消息,也没有创建一个本地分支 origin / release (根据 git checkout man 页面)。我仍然在 master。注意,如果我做了 git checkout refactor-update 一切都按预期工作。



这可以在其他计算机上重现(尽管相同的平台和可能相同版本的git)。我有(出于绝望,不是因为我认为它会工作),删除了 release 分支,并用备份替换它, master git push origin:release&& git push origin master:release



我被困在可能导致问题的原因。我怀疑是因为某些原因 git checkout 似乎没有识别出版本这个字,就像执行 git checkout 一样。为了尝试跟进此事,在另一个回购协议中,我创建了一个发布分支来查看它是否是保留字或其他内容,但它绝对只是在此存储库中。在 .git / config 中似乎没有任何异常。



Git版本:1.8

解决方案

在我的情况下,问题是我的文件夹与我的项目根目录中的分支名称相同。 Git似乎认为 git checkout xyz 中的 xyz 是文件夹,而不是分支。



我必须执行以下操作来将我的工作树第一次切换到分支 xyz
$

显然,这增加了几行到 code> .git / config (也可能是其他配置文件)。之后,我可以通过调用 git checkout xyz 来切换 xyz master code> / git checkout master



当我在根文件夹中并调用 git checkout xyz 在我克隆回购后,git什么都不做,也没有给出任何回应。当我 cd 到一个子文件夹,以便文件夹 xyz 不在范围内,然后调用 git checkout xyz ,git抱怨: error:pathspec'xyz'与git 已知的任何文件都不匹配。 p>

TLDR: If X exists as a remote branch, then git checkout X should create a local branch of it. In my case, for a single branch, it does not.

The remote repository has a master, release, and some other branches (say refactor-update) I do:

git clone WHATEVER/repo.git
git checkout release

But I do not get the normal branch switch message, nor is a local branch tracking origin/release created (per the man page for git checkout). I am still on master. Note that if I do git checkout refactor-update everything works as expected.

This is reproducible on other computers (though the same platform and likely the same version of git). I have (out of desperation, not because I thought it would work), removed the release branch and replaced it with a backup and master respectively with no change in behaviour (git push origin :release && git push origin master:release)

I am stuck for what might be causing the problem. My suspicion is that git checkout doesn't seem to recognize the word release for some reason, which would make it much like executing just git checkout. To try and follow up on this, in another repo I created a release branch to see if it was a reserved word or something, but it is definitely just in this repository. There doesn't seem to be anything out of the ordinary in .git/config.

Git version: 1.8

解决方案

In my case, the problem is that I have a folder with the same name as the branch in the root of my project. Git seems to think the xyz in git checkout xyz is the folder, not the branch.

I had to do the following to switch my working tree to branch xyz for the first time:

git checkout -t origin/xyz

Apparently, this adds a few lines to .git/config (and maybe other configuration files). After that, I can switch between xyz and master just by calling git checkout xyz / git checkout master.

When I'm in the root folder and call git checkout xyz right after I cloned the repo, git does nothing and doesn't give any response either. When I cd to a sub-folder so that the folder xyz is not in scope anymore and then call git checkout xyz, git complains: error: pathspec 'xyz' did not match any file(s) known to git.

这篇关于为什么git checkout< remote_branchname>不创建新的跟踪分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆