Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge between multiple forked repositories on GitHub?

Tags:

git

github

fork

I'm still very new to coding and Github and as such am a little confused with how forking repos works - so please forgive what may be a basic question.

I've been working on a project with different pair partners all week and my current code base situation is as follows:

My initial repo - https://github.com/timrobertson0122/yelp_clone

This code was then forked and work continue on a second repo - (can't post url)

That repo was subsequently forked and contains the most recent code, that I worked on with a colleague yesterday, which I can't fork - https://github.com/curlygirly/yelp_clone-1

So my question is how do I sync my original repo? Can I just add an upstream to the most recently forked repo that points to the original repo? Do I need to submit pull requests?

Thanks.

like image 447
Tim Robertson Avatar asked Jun 18 '15 07:06

Tim Robertson


People also ask

How do I merge fork repositories?

Simply push your development branch to the forked remote repository and create the pull request as described in the linked article. The owner of the original repository can then add your repository as a new remote repository, fetch your changes and merge your development branch back into the master branch.

Can you merge two GitHub repositories?

You can merge repository A into a subdirectory of a project B using the subtree merge strategy. This is described in Subtree Merging and You by Markus Prinz. (Option --allow-unrelated-histories is needed for Git >= 2.9.

Can you fork a forked repository?

You can fork any repo by clicking the fork button in the upper right hand corner of a repo page. Click on the Fork button to fork any repo on github.com. Source: GitHub Guides.


1 Answers

You can add curlygirly's repo as a remote to your original repo and merge in changes from it just like any other branch. For example, if you want to merge everything on curlygirly's master branch into your original repo's master:

git remote add curlygirly https://github.com/curlygirly/yelp_clone-1.git
git fetch curlygirly
git checkout master
git merge curlygirly/master

You can also do this using Pull Requests if you prefer, want to put it through code review, etc. Simply open a request from curlygirly:master (or any other branch) to timrobertson0122:master and go from there.

The great thing about Git is that repositories, branches, commits, etc. are all just building blocks you can manage any way you like. There's nothing special about your first repo, origin, or master, so you're free to work on code anywhere, and move it anywhere else later.

like image 96
Kristján Avatar answered Oct 11 '22 00:10

Kristján