• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

A git merge question!!

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a test branch and of course there is a master branch!!
The master branch contains several projects.
I have made several changes to 'one' of those projects.
So master is ahead on all the other projects, and behind on mine.

There is one other developer working on the same project as me, but she is working directly on master.

I'd like to merge my branch into master :/

This is how I 'think' it should go.

git checkout test
git pull --rebase (make sure my test branch is up to date)
git merge master (make sure my branch is in sync with master as much as possible, whilst preserving my changes).
'git add file xyz and so on to resolve any conflicts
git checkout master
git merge test (I believe this should now work smoothly without conflict).

2 questions:

#1 Do my steps look correct?
#2 After a git merge, is it necessary to do a git push? (both master and test are remotes
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I usually go about this is by using git rebase. So my steps would be something like this (right from the very beginning before changing anything in my test branch):



If there are any conflicting changes, the rebase process will pause and show you the conflicts and you can then fix the conflicts and do a git add/rm depending on the way you want to resolve them and then continue the rebase by issuing git rebase --continue


Once the rebase is complete your local test branch will now have all the commits from remote master branch plus your local commit on top of them. Remember though that all of this is still local. So if you want to push this to the test branch of the remote repo you just issue a push:

 
Billy Sclater
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks (:

But, will this rebase, rewrite the history of my test branch?
So when I do a :

in my test branch, will it now show the master history?

 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. So if your test branch earlier had:


Assume you were the one who did the local commit xyz and commit pqr after you had created the test branch from the master branch. Now assume your teammate did a commit mno in the remote master branch. Now when you do the rebase as I suggested in the previous post, after a successful rebase the commit history will be:



So as you can see, the local commits were literally rebased "on top of" what's there in the remote master branch.

By the way, this (free online) book explains all of this in a very good and simple to understand terms http://git-scm.com/book
 
Billy Sclater
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, and thanks for the book!!

So, also just out of curiosity, would the steps in my original post also work?
 
Billy Sclater
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Followed the instructions, however I had one anomaly!!!

In my test branch I had an extra folder 'utils'.

After running:


The folder had been removed, also there was no mention of it being removed in the console :/

Any idea why this happened? And how to avoid it?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was that folder added (using git add) or committed (using git commit) to your local test branch? Or was it just lying around untracked?

 
Billy Sclater
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added everything yesterday using:

from my project root.

Then:


Then:


Today, I immediatley ran:
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic