0

I have a Php project in Laravel framework.

Initial CODE STATE : A

One month later , another developer joins me.

After 6 months ,

My CODE STATE : A + B

His CODE STATE : A + C

B and C have many common files so we are expecting conflicts during git merge. We now wish to have a code base : A + B + C

My current status/strategy-in-progress : I have set up a remote git repository with code A + C and local git repository with A + B .

how to best merge remote git repository(A+B) with my local git repository(A + C) so that i have A+B+C on the both local and remote git repo?

Please assist!

Jay Teli
  • 530
  • 1
  • 11
  • 19

2 Answers2

0

Let's assume that A + C is in master, and A + B is in a pull request branch. If B and C modified the same files, they may cause merge conflicts with each other, so you want to resolve these before merging your pull request branch into master to make it easier to review and integrate. As a result, you should either merge master into your pull request branch (which will add a merge commit with parents B and C) or rebase your pull request branch against master (which will change your branch's commits to A + C + B).

Nick McCurdy
  • 17,658
  • 5
  • 50
  • 82
  • Thank your for reply. If i create a pull request , i will have A + B in local. If i copy-paste my A+C into the folder then B is replaced by C.. Can you elaborate your solution so that how to merge C with the pull request. P.S.I am a beginner. – Jay Teli Dec 03 '15 at 16:12
  • My current knowledge about git is what i learnt in git series by Jeffrey Way https://laracasts.com/series/git-me-some-version-control/ – Jay Teli Dec 03 '15 at 16:15
  • How ? "so you want to resolve these before merging your pull request branch into master to make it easier to review and integrate" – Jay Teli Dec 03 '15 at 23:16
0

I suggest you to make two branches from A, for example: MY_A and HIS_A then you can add B and C to your branches: MY_A + B and HIS_A + C solve conflict, then try to add the rest of the work to both and choise the easiest to solve like this:

MY_A + B + C or HIS_A + C + B

but using branches you never lost your work and always you can do this localy for not alter the repository

Update:

first pull you master branch (A+C):

$ git pull origin master

then create a branch from master branch an create AC:

$ git checkout -b AC master

before change to the other branch ensure to have all your work commited

then create another branch from master branch an create AB:

$ git checkout -b AB master

here you are in other branch, you can add his code and commit it without worry about to delete or change files

see your branches use:

$ git branch

change to a branche AC use:

$ git checkout AC

change to branche AB use:

$ git checkout AB

Now you have two branches that you can see the diff read this, and use git diff AC..AB to see the diference in the terminal, and what will happend if you do a merge between two branches.

Community
  • 1
  • 1
Simon Puente
  • 451
  • 1
  • 8
  • 21
  • Thank you for reply but the problem is I no longer have A, I have only A+B and A+C. and i need A+B+C – Jay Teli Dec 03 '15 at 16:27
  • Did you tried to make a diff between your: A+B and A+C? – Simon Puente Dec 03 '15 at 16:29
  • no .. how to diff between 'A+B' and 'A+C' . (I am on Ubuntu and i use Sublime text 3 editor) – Jay Teli Dec 03 '15 at 16:31
  • take a look [at this](http://stackoverflow.com/questions/9834689/comparing-two-branches-in-git) you can use the command line or a graphic tools like smartGit to help you – Simon Puente Dec 03 '15 at 16:34
  • [This](https://www.atlassian.com/git/?utm_source=bitbucket&utm_medium=link&utm_campaign=help_dropdown&utm_content=learn_git) is a good place to learn how to use git – Simon Puente Dec 03 '15 at 16:38
  • Thankyou for your reply..How to create two branches - One with A+B and other with A+C ?If i clone the remote repo , i have A+C in my master branch ... If i copy-paste A+C in the cloned folder i lose changes of B – Jay Teli Dec 03 '15 at 16:42
  • Where you have A+B? is it in another repository or you just have the code? – Simon Puente Dec 03 '15 at 16:47
  • A+B is code.. not a repo.. i did git init to make it local repo – Jay Teli Dec 03 '15 at 16:48