I have what I believe is a very common scenario:
- I clone a development branch of an open source project.
- I then create a branch called mychanges, where I add some code to the project.
Now all I wish to do is be able to update the development branch so it reflects the latest development version, but at the same time be able to keep my changes.
How can this be achieved?
I made the following test:
- Created a notes.txt on a master
- Branched to mychanges and checkout it out
- Added a line
- Merged to master
- Deleted the line in the version on master
- Now the master has a version without the added line, the mychanges branch has it with, but if I try to merge mychanges to the master again git says ‘Already up-to-date’.
Also reports conflict if I merge the development branch to the mychanges one
Thanks!
This is because the branch
mychangesis behind yourmasterbranch. That is,mastercontains all the changes that occured inmychanges.Having a conflict while merging two differing branches is normal; it just means that the two branches have different, conflicting changes in them, and that the merge cannot be automatically completed. I would guess that you’ve edited a file that is on the
developmentbranch, and thatgitis unable to work out if you want to keep the changes from branch development or mychanges.When
gitis unable to automatically merge, (that is, it is unable to determine which changes to a file to keep and which to discard in the merge), you can select the changes yourself, then re-merge the branches. This lets you select which changes you want; if you want the changes that were from thedevelopmentbranch, you can keep them. If, however, you have changed the same lines of code that were changed ondevelopment, you may want to keep those instead.You should read the progit book, specifically chapter three, which will teach you about branches and, in chapter 3-6,
rebasingyour changes on top of the new changes fromdevelopment.The progit book is a great source of information about using
git, and it will probably answer some of your questions.