Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep a branch synchronized/updated with master?

At the moment git is doing my head in, I cannot come up with the best solution for the following.

There are two branches, one called master and one called mobiledevicesupport. I want to keep mobiledevicesupport as a continuous branch that will be merged/synced with the master branch whenever mobiledevicesupport is stable. This would merge changes from mobiledevicesupport into master but also bring all the changes from master into mobiledevicesupport so that branch can continue to be worked on and the features improved or amended. This needs to work with a central repository and multiple developers.

Please an example of similar workflows other people use or just tell me if this idea is stupid and I should consider other options. At the moment the workflow seems sound, but I just don't know how I can make git work this way.

Thanks, all help much appreciated.

Update 1: If I was to merge master into mobiledevicesupport and mobiledevice support into master, do I get replicated commits across both branches. Or is git smart enough to work out that I have pulled the latest changes from branch A into branch B and add merge commit C to branch B. And I have pulled the latest changes from branch B into branch A and add merge commit D to branch A?

I was going to post an image but I don't have enough reputation for it, so I guess the following illustration will have to do. Two branches continuously running with merges going both directions often. The key thing I am not sure about is how git will play out the commits and will it fill either branch with the commits from the other branch on merges or will it stay clean. I have used rebase before but it seems to end the branch and put all the commits into the master, or I did it wrong. Thanks for the help so far.

master A--B--C-----H--I--J--M--N        \   /    \ mobile  \ /      \ D--E--F--G--------K--L 
like image 515
Mr. EZEKIEL Avatar asked May 02 '13 03:05

Mr. EZEKIEL


People also ask

How do I sync master with branch bitbucket?

Sync a branch to the mainlineFrom the left sidebar, click Branches. Locate the branch you created. From the Commits tab, click Sync now. Bitbucket tries to automatically merge for you but only performs primitive merges.


2 Answers

yes just do

git checkout master git pull git checkout mobiledevicesupport git merge master 

to keep mobiledevicesupport in sync with master

then when you're ready to put mobiledevicesupport into master, first merge in master like above, then ...

git checkout master git merge mobiledevicesupport git push origin master 

and thats it.

the assumption here is that mobilexxx is a topic branch with work that isn't ready to go into your main branch yet. So only merge into master when mobiledevicesupport is in a good place

like image 168
concept47 Avatar answered Oct 10 '22 17:10

concept47


Whenever you want to get the changes from master into your work branch, do a git rebase <remote>/master. If there are any conflicts. resolve them.

When your work branch is ready, rebase again and then do git push <remote> HEAD:master. This will update the master branch on remote (central repo).

like image 29
euphoria83 Avatar answered Oct 10 '22 17:10

euphoria83