Git从另一个存储库中提取分支? [英] Git pulling a branch from another repository?

查看:105
本文介绍了Git从另一个存储库中提取分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地git仓库,它是github上仓库的一个克隆。有人已经分叉了存储库并在新的存储库中对新分支进行了更改。我想将这个新分支移动到我的仓库中(在与主人合并之前先在本地处理它)。

I have a local git repository which is a clone of a repository on github. Someone has forked the repository and made changes in a new branch on a new repository. I want to move this new branch into my repository (locally to work on it first before merging with the master).

我试着创建一个新分支,然后从分叉的存储库,但它抱怨,因为新的分支是主分支的副本以及本地文件更改,所以它说

I tried creating a new branch and then pulling from the forked repository but it complains because the new branch is a copy of the master branch as well as the local file changes, so it says

错误:您对本地文件的更改将被merge 所覆盖。

那么,如何将其他存储库中的分支引入新分支在我的本地存储库?

So how can I pull the branch in the other repository into a new branch on my local repository?

我希望这是有道理的。如果没有,这是我的存储库: https://github.com/MatthewLM/cbitcoin

I hope that makes sense. If not, this is my repository: https://github.com/MatthewLM/cbitcoin

正如你所看到的,有人已经创建了一个分支为linuxBuild的新存储库: https://github.com/austonst/cbitcoin/tree/linuxBuild

As you can see, someone has created a new repository with the branch "linuxBuild": https://github.com/austonst/cbitcoin/tree/linuxBuild

我希望我的本地存储库上的分支用于MatthewLM / cbitcoin。

I want that branch on my local repository for MatthewLM/cbitcoin.

我该如何操作?

How can I do this?

推荐答案

您需要确保 git status 显示您的本地存储库中不存在未分离的更改。

您可以通过首先存储本地更改来执行此操作,并且拉动那个分支。之后,您可以应用您的存储。

You need to make sure that git status shows that no unstaged changes exist in your local repository.
You can do this by first stashing your local changes and than pulling that branch. Afterward you can apply your stash.

如果要在本地存储库中重新创建分支的分支结构,您可以执行以下操作:

If you want to re-create the branch structure of the fork in your local repository, you can do the following:

git remote add fork <url of fork>
git fetch fork
git checkout -b fork_branch fork/<branch>

这将创建本地分支 fork_branch ,并且在fork中也有类似于< branch> 的历史记录,即 fork_branch 将会从 master 其中< branch> 在fork中执行。
此外,您的本地分支现在将跟踪分支中的那个分支,这样您可以轻松地引入分支中提交的新更改。

This will create the local branch fork_branch with the same history like <branch> in the fork, i.e. fork_branch will branch off of your master where <branch> does in the fork. Additionally, your local branch will now track that branch in the fork, so you can easily pull in new changes committed in the fork.

我认为你仍然需要事先确定您的工作副本不包含任何更改。

I think you still need to make sure beforehand that your working copy doesn't contain any changes.

这篇关于Git从另一个存储库中提取分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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