OscarRyz
OscarRyz

Reputation: 199195

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.

Q1. What commands are needed for him to see these changes?

#me 
git commit 
git push 
#him
?
? 
?

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.

Upvotes: 0

Views: 3432

Answers (2)

Kevin Jalbert
Kevin Jalbert

Reputation: 3235

To my understanding you have 2+ users working on one github repository. You are working directly off of the created github repository, while another person forks the github repository and works on their own fork.

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. 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.

You can use hub to make pull requests through the command-line if you want or through the GitHub web-interface.

Upvotes: 3

Michael Mior
Michael Mior

Reputation: 28753

To get changes, you just use git pull assuming you're both using the same remote. If your remote is your Github repo, and his remote is the fork, then you'll need to add his fork as a remote. (And he'll have to add your original repo as a remote as well). See managing remotes from the Github documentation.

Upvotes: 2

Related Questions