Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge branch of forked repo into master branch of original repo?

There is an open source project on GitHub. Its original repo contains the most recent master branch. Now there is someone (not me) who has forked this repo, created a development branch from the master branch and added stuff to the development branch. What I would like to do now is to merge the development branch back to the master branch. Unfortunately, the master branch of the forked repo is not up-to-date. Also note that I'm not in possession of the two respective remote repos.

At the moment, I have cloned both the original repo and the forked repo to my local machine using git clone. How can I merge the development branch of the forked repo into the master branch of the original repo on my local machine (i.e. not on the remote server which is not possible anyway)?

like image 489
pemistahl Avatar asked Jan 29 '13 16:01

pemistahl


People also ask

How do I merge fork branches?

Fork now allows for a more intuitive way to merge and rebase branches – drag & drop. Use the mouse to drag a branch on the sidebar into another branch, and choose whether to merge or rebase from the resulting popover.

How do I merge branches into master branches?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch.


1 Answers

When using GitHub, you could do this using a Pull Request. 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.

It is usually not necessary for your master branch to be fully up-to-date -- although it is extremly helpful, especially when merging the development branch.

First, you should bring the master branch in the forked repository up-to-date:

$ git remote add upstream ssh://path/to/original/repo $ git checkout master $ git fetch upstream # Instead of "fetch" & "merge", "pull" would also work $ git merge upstream/master  

Then either rebase or merge your development branch into the master branch:

$ git checkout development $ git rebase master # OR "git merge master" 

Resolve any conflicts, if necessary. When merging, use git commit to finish the merge, when rebasing use git commit && git rebase --continue.

You should now be able to git push to the origin of the forked repository, and create a pull request. Alternatively, if you're authorized to do so, you can also push directly to the original repository from your fork.

like image 60
helmbert Avatar answered Oct 10 '22 22:10

helmbert