简体   繁体   English

同步两个git(或github)存储库

[英]Synchronize two git ( or github ) repositories

I've found a number of resources in internet including two questions here in SO but it is not clear to me what are the commands to execute. 我在Internet上找到了很多资源,包括SO中的两个问题,但我不清楚要执行哪些命令。

  • I have a git repo ( in github ) someone forks it and create a local copy 我有一个git repo(在github中)有人分叉它并创建本地副本
  • I create a local copy of my own. 我创建自己的本地副本。

Q1. Q1。 What commands are needed for him to see these changes? 他需要什么命令才能看到这些变化?

#me 
git commit 
git push 
#him
?
? 
?

Q2. Q2。 If he makes some changes what commands do I need to have those changes? 如果他进行了某些更改,那么我需要执行哪些命令?

#him
git commit
git push 
# me 
?
? 

This might be a very easy question but I don't seem to find the answer. 这可能是一个非常简单的问题,但我似乎找不到答案。

To my understanding you have 2+ users working on one github repository. 据我了解,您有2个以上的用户在一个github存储库上工作。 You are working directly off of the created github repository, while another person forks the github repository and works on their own fork. 您直接在创建的github存储库中工作,而另一个人则在github存储库中进行分叉并在自己的分叉中工作。

For the two repositories to synchronize you would need to add each other as a remote. 为了使两个存储库同步,您需要将它们彼此添加为远程对象。 From my experience when you fork a repository I typically make an upstream remote so I can then pull in changes from the original repository that I forked from. 根据我的经验,当您创建一个存储库时,我通常会创建一个上游远程服务器,这样我就可以从分叉的原始存储库中提取更改。

git remote add upstream <others-git-url>
git pull upstream <branch>

The two previously mentioned commands will allow the person who forked from the original repository to pull in changes from the original to their forked repository. 前面提到的两个命令将允许谁从原来的库叉从原始到他们的分叉库更改拉人。

As for the other way around, you can just apply the same concept for the other person (possibly call the new remote downstream ). 至于其他方法,您可以将相同的概念应用于其他人(可能称为新的远程下游 )。


As a side note it might work out smoother if the person who forks the repository just submits a pull request that the other users can just work from. 附带说明一下,如果分叉存储库的人仅提交其他用户可以使用的拉取请求 ,则可能会更顺畅。 This way multiple users can work on a single branch effectively simplifying the synchronization. 这样,多个用户可以在单个分支上工作,从而有效简化了同步。 When the pull request is completed then the changes can be pushed into the master branch of the original github repository. 拉取请求完成时,可以将更改推入原始 github存储库的master分支中。 An alternative is to just work in the same github repository (make a new branch for the new collaborative work), though this really comes down to the current work/collaborative situation. 另一种选择是只在同一个github存储库中工作(为新的协作工作创建一个新分支),尽管这实际上取决于当前的工作/协作情况。

You can use hub to make pull requests through the command-line if you want or through the GitHub web-interface. 您可以根据需要使用集线器通过命令行或通过GitHub Web界面发出拉取请求

To get changes, you just use git pull assuming you're both using the same remote. 要获取更改,只需使用git pull前提是两者都使用同一个遥控器。 If your remote is your Github repo, and his remote is the fork, then you'll need to add his fork as a remote. 如果您的遥控器是您的Github存储库,而他的遥控器是fork,那么您需要将他的fork添加为遥控器。 (And he'll have to add your original repo as a remote as well). (而且他还必须将您的原始存储库添加为远程存储库)。 See managing remotes from the Github documentation. 请参阅Github文档中的管理遥控器

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

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