简体   繁体   English

Git 两个原点,从一个拉到另一个

[英]Git two origins in which pull from one and push to another

I have two origins in my git local one is original(A) from where I Had cloned code and other is my own repository(B).我的 git 本地有两个来源,一个是我克隆代码的原始(A),另一个是我自己的存储库(B)。 I have to push to B changes from A + my local changes.我必须从 A + 我的本地更改推送到 B 更改。 What are the commands so that this happens smoothly.有什么命令可以顺利进行。 Please explain how will your commands work in context of HEAD and commits.请解释您的命令将如何在 HEAD 和提交的上下文中工作。

It's important to note that origin is just the default name for most remote repositories, they can be called anything.重要的是要注意origin只是大多数远程存储库的默认名称,它们可以被称为任何东西。 In this example we will use originA and originB , and assume all work is done in master for the sake of simplicity.在这个例子中,我们将使用originAoriginB ,并且为了简单起见,假设所有的工作都在master中完成。

To set up a new remote repository:要设置新的远程存储库:

git remote add originA https://github.com/user/repositoryName.git

To change the URL of an existing repository, replace add with set-url in the previous command.要更改现有存储库的 URL,请将上一个命令中的add替换为set-url

To fetch all the commits from originA and merge them into the local master branch run:要从originA获取所有提交并将它们合并到本地master分支中,请运行:

git pull originA master

If there are no merge conflicts, originA/master and local master will be the same and HEAD will be set to the most recent commit.如果没有合并冲突, originA/master和本地master将相同,并且 HEAD 将设置为最近的提交。

Then set up originB as described above (if not already set up) and make any local commits, which can be pushed by running:然后如上所述设置originB (如果尚未设置)并进行任何本地提交,可以通过运行来推送:

git push originB master

This assumes your local repo has all the commits originB does, the push will be blocked if not.这假设您的本地仓库具有originB所做的所有提交,否则推送将被阻止。 The only way to push code directly between originA and originB would be to log in to one of those servers, otherwise the code has to be bounced between your local repository.originAoriginB之间直接推送代码的唯一方法是登录到其中一台服务器,否则代码必须在本地存储库之间反弹。

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

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