无法同时创建本地和远程分支(跟踪) [英] Can not create a local and remote branch (tracking) at the same time

查看:550
本文介绍了无法同时创建本地和远程分支(跟踪)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pro Git


如果您愿意,您可以设置其他跟踪分支 - 不是
的分支在原点上跟踪分支并且不跟踪主分支。简单的
例子就是刚刚看到的例子,运行git checkout -b [branch]
[remotename] / [branch]



$ git checkout --track origin / serverfix分支serverfix设置为
跟踪远程分支refs / remotes / origin / serverfix。切换到新的
分支serverfix

$ p $ git checkout -b sf origin / serverfix分支sf设置为跟踪
远程分支refs /遥控器/产地/ serverfix来。切换到新的
分支sf


我的理解是,这提供了创建本地分支和上游分支。

但是当我这样做时:

git checkout -b iss53 origin / iss53 我得到:

致命:不能更新路径并同时切换到分支'iss53'。



当我这样做时:

git checkout --track origin / iss53 我得到:


致命:无法更新路径并在相同的
时间切换到分支'iss53'。您是否打算签出'origin / iss53'不能被
解析为提交?


为什么?

解决方案

 无法更新路径并切换到分支

正如我在使用git获取新的上游分支,你可以试试:

 #让我们先创建一个新的本地分支
git checkout -b iss53
#然后重置它的起点
git reset --hard origin / iss53

确保远程跟踪分支 origin / iss53 首先存在(在 git fetch origin 之后)

origin / iss53 表示在 iss53 a / 2749166/6309>上游远程回购引用由 origin



如果没有这样的分支,那么您只创建一个本地分支 iss53 ,然后像这样推送它:

  git push -u origin iss53 

这将在本地分支 iss53 和远程跟踪分支 origin / iss53 (跟踪新创建的分支 iss53 on origin ,由推送创建)。



请参阅为什么我需要明确推送一个新的分支?以获取更多关于此次推送的信息。


From Pro Git:

you can set up other tracking branches if you wish — ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]

$ git checkout --track origin/serverfix Branch serverfix set up to track remote branch refs/remotes/origin/serverfix. Switched to a new branch "serverfix"

$ git checkout -b sf origin/serverfix Branch sf set up to track remote branch refs/remotes/origin/serverfix. Switched to a new branch "sf"

My understanding is that this presents a way to create a local branch and an upstream branch.

But when I do:

git checkout -b iss53 origin/iss53 I get:
fatal: Cannot update paths and switch to branch 'iss53' at the same time.

And when I do:
git checkout --track origin/iss53 I get:

fatal: Cannot update paths and switch to branch 'iss53' at the same time. Did you intend to checkout 'origin/iss53' which can not be resolved as commit?

Why?

解决方案

Cannot update paths and switch to branch

As I mention in "Get new upstream branch with git", you can try:

# let's create a new local branch first
git checkout -b iss53
# then reset its starting point
git reset --hard origin/iss53 

Make sure that the remote tracking branch origin/iss53 does exist first (after a git fetch origin)

origin/iss53 means there was a iss53 on the upstream remote repo referenced by origin.

If there was not such a branch, then you only create a local branch iss53, and push it like so:

git push -u origin iss53 

That would establish an association between the local branch iss53 and the remote tracking branch origin/iss53 (tracking the newly created branch iss53 on origin, created by the push).

See "Why do I need to explicitly push a new branch?" for more on that initial push.

这篇关于无法同时创建本地和远程分支(跟踪)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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