2

I've forked a repo at GitHub for OpenCart, and it contains several branches

master development-feature-profiles v1.5.5.1 v1.5.5.2 v1.5.6 v1.5.6.1 

The current master branch has all the changes in it for the upcoming version 2.0.

I've created my own branch, based on the master branch, let's call it:

development-2 

It has a bunch of changes I've made to the core files etc. I'm not interested in doing a pull-request to opencart for these changes, or more accurately, they're not interested in merging my changes, so that's fine.

I'm leaving the master branch as is and pulling their updates into it.

My question is, how can I merge the new changes from the master that come as they continue to update the opencart/opencart repo that I've forked into my development branch, without overwriting my changes?

I assume that I have to create some sort of diff and patch but I'm unclear on how and I can't fine any instructions online.

1 Answer 1

1

If you share your development-2, you should merge the master in your development-2. Your history looks then like this:

 *- [patch to make development-2 compatible to new master] : : |,-------------------*- merge | | :- [some work ...] :- [some work ...] | | |,-------------------*- merge | | :- [some work ...] :- [some work ...] | | *- master *- development-2 : : 

If you dont share your code or you don´t care other developers repository you can use a git pull --rebase. Maybe you have to add one patch in development-2 to make the branch compatible to the new master.

Then the history looks like this:

 *- development-2 :- [some work] * ,-------------------* *- master 

if master is updated and you use git pull --rebase than it looks like so

 *- [patch to make development-2 compatible to new master] *- development-2 :- [some work] * ,-------------------* *- master * :- [some work ...] *- [old master] 
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for the help. I'm still not exactly sure I understand. So let's say today Daniel make 2 new commits to the Opencart master repo. I then pull those commits into my master repo. Then I can checkout development-2 and merge the master into it, and none of my changes will be overwritten? That seems to be what you're suggesting but just to make sure so I don't botch my code. I put in quite a bit of work on this new breadcrumb class and I don't want it to be lost in my branch.
Exactly, the magic lies in the word merge. :-) If the changes not on the same place in one file you have no merge-conflicts. But if the master changed on the same place in a file, than you get merge conflicts. You have to resolve this situation.
I guess where I'm not understanding is that the files they are working on will NEVER have my changes in them. So for instance if I have a file example.php and I've made changes to that file, they don't have those changes in their example.php file. So if they make changes to that file I've committed mine, and I merge that file, how is it that my changes will not be erased by the new file? Sorry to be dense, just my first time working with a public repo. Usually I just clone it and keep my own version.
No problem - try and make a testrepository. first a master branch in wher is a file like test.txt. then make a dev-branch change something, commit it. Back to master, some changes again in test.txt. commit them and now. switch to development and make a merge git merge --no-ff master. Now a MERGE is commited with or without conflicts...
Thank you very much silvio, you've been a great help, I appreciate your time.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.