Git 从不同的存储库中拉取一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39538520/
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
Git pull a branch from a different repository
提问by SpiXel
I've few files in my current repository. I want to merge a remote branch from a different repository.
我当前存储库中的文件很少。我想合并来自不同存储库的远程分支。
- Pull and merge a branch from
github.com/username/code.git
(branch loader) - Then pull and merge a branch from
github.com/username/code.git
(branch login)
- 从
github.com/username/code.git
(分支加载器)拉取并合并一个分支 - 然后从
github.com/username/code.git
(分支登录)拉取并合并一个分支
Is it possible or what's the workaround? I wanna keep adding code to my current branch from different remote branches.
是否有可能或解决方法是什么?我想继续从不同的远程分支向我的当前分支添加代码。
回答by SpiXel
You can add other origins for your repository using
您可以使用为您的存储库添加其他来源
git remote add new_origin git@theUrlToRepo
You can now start pushing/pulling and basically doing all operations on both of your remotes.
您现在可以开始推/拉并基本上在您的两个遥控器上进行所有操作。
git push origin master
git push new_origin master
git pull origin master
git pull new_origin master
You just have to specify which remote you're doing your operations with and you're set.
您只需要指定您正在使用哪个遥控器进行操作并进行设置。
In your specific usecase, after adding remote repos and naming them, you'd do something like the following to merge remote branches into your local workspace.
在您的特定用例中,在添加远程存储库并命名它们后,您将执行以下操作以将远程分支合并到本地工作区。
git merge origin/loader
git merge new_origin/login
回答by j2emanue
do this from your original repo that you want to merge the new code into:
从您要将新代码合并到的原始存储库中执行此操作:
for me i just created a new branch with the same name first:
对我来说,我只是先创建了一个同名的新分支:
git checkout -b my_new_branch
then i added the other origin:
然后我添加了另一个来源:
git remote add new_origin http://someRepo.git
then i simply pulled the branch from new_origin into my current repo:
然后我只是将分支从 new_origin 拉到我当前的仓库中:
git pull new_origin my_new_branch
the git pull command should do a fetch and merge for you.
git pull 命令应该为你做一个获取和合并。
回答by pedrotester
You can just
你可以
git pull url branch
git pull url 分支
it works
有用
回答by vin
You can also do
你也可以这样做
git pull <git_pull_url> <branch> --allow-unrelated-histories