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.

secondman
  • 3,233
  • 6
  • 43
  • 66

1 Answers1

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]
silvio
  • 2,174
  • 20
  • 36
  • 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. – secondman Dec 24 '13 at 09:57
  • 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. – silvio Dec 24 '13 at 10:32
  • 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. – secondman Dec 24 '13 at 10:38
  • 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... – silvio Dec 24 '13 at 10:54
  • Yeah that's kinda what I did. I created a new branch based off dev-2 and merged master into it. I had one conflict. I use GitTower on Mac so I just resolved the conflict with the Use Theirs tool then redited the changes that were overwritten. This could be really problematic though if they add a bunch of changes to files I've written to. – secondman Dec 24 '13 at 11:07
  • Thanks for your help. Cold you possibly take a look at this question too http://stackoverflow.com/questions/20759571/line-ending-problems-in-git – secondman Dec 24 '13 at 11:11
  • I have looked, I can not help because I have no OSX, but a quick search showed me this: http://stackoverflow.com/questions/2825428 – silvio Dec 24 '13 at 11:14
  • 1
    Thank you very much silvio, you've been a great help, I appreciate your time. – secondman Dec 24 '13 at 11:20