简体   繁体   English

无法从上游创建新分支

[英]Failed to create a new branch from upstream

I wanted to create a new branch from upstream. 我想从上游创建一个新分支。 What I did are 我所做的是

$ git init
$ git clone https://github.com/nalam-nmef/LearnGitWithGithubFlow.git
$ git remote add upstream https://github.com/twentyTwo/LearnGitWithGithubFlow.git

then, to create a new branch from upstream 然后,从上游创建一个新分支

$ git checkout -b changes1 upstream/master

But in this point an error occurs. 但是在这一点上会发生错误。 It says 它说

fatal: Cannot update paths and switch to branch 'changes1' at the same time. 致命:无法更新路径并不能同时切换到分支“ changes1”。 Did you intend to checkout 'upstream/master' which can not be resolved as commit? 您是否打算检出无法解决为提交的“上游/母版”?

What I will do after that is pushing that new branch to my fork 之后我要做的就是将新分支推到我的叉子上

$ git push -u origin changes1

That is, I always create a branch for a new change request locally. 也就是说,我总是在本地为新的更改请求创建一个分支。 The branch is created from the upstream/master branch. 该分支是从上游/主分支创建的。 Commit changes locally and push it to my fork. 在本地提交更改并将其推送到我的fork。 Then, create a pull request to the upstream master. 然后,创建对上游主服务器的拉取请求。 But, I am getting the error in $ git checkout -b changes1 upstream/master 但是,我在$ git checkout -b changes1 upstream/master收到错误。

Whats the wrong with this? 这怎么了? What is the best practice? 最佳做法是什么?

You need to fetch upstream first. 您需要先获取upstream

git fetch upstream
git checkout -b changes1 upstream/master

By default, only origin was cloned/fetched. 默认情况下,仅克隆/获取origin
Type: 类型:

git remote -v

You will see your remotes. 您将看到您的遥控器。

Ideally, upstream URL should not be the same as the origin one (which should be your fork). 理想的情况下, upstream网址应该是相同的origin一个(这应该是你的叉子)。
upstream should refer to the original repo URL that was forked. upstream应引用已分叉的原始回购URL。


Second, don't do: 第二,不要做:

git init
git clone ...

That would clone a git repo inside another git repo, which is why git remote -v only shows upstream. 那会另一个git repo中克隆一个git repo,这就是为什么git remote -v只显示上游。

Try instead: 请尝试:

cd /a/path
git clone https://github.com/twentyTwo/LearnGitWithGithubFlow.git
cd LearnGitWithGithubFlow
git checkout -b changes1

(no need for origin/master: by default, origin/master is checked out already) (不需要原始/母版:默认情况下,原始/母版已签出)

So, in brief, these are the steps if you want to create a new branch from an upstream branch 因此,简而言之,如果您想从上游分支创建新分支,请执行以下步骤

  • First fork the desired repo; 首先分叉所需的仓库;
  • Clone your forked repo 克隆您的分叉存储库
  • cd in the repo 光盘在回购
  • Add upstream 添加上游
  • Fetch the upstream 获取上游
 git clone https://github.com/forkedRepo/demoRepo.git cd demoRepo\\ git remote add upstream https://github.com/originalRepo/demoRepo.git git fetch upstream 
  • create a new branch from upstream 从上游创建一个新分支

git checkout -b newLocalBranchName upstream/fromUpstreamBranch git checkout -b newLocalBranchName上游/从上游分支

  • Push that new branch to my fork 把那个新分支推到我的叉子上

git push -u origin newOriginBranchName git push -u origin newOriginBranchName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM