[dev] Fwd: Rebase vs. Merge

Michael Rubinsky mrubinsk at horde.org
Wed Jan 13 19:08:02 UTC 2010


Quoting Ben Klang <ben at alkaloid.net>:

> On Jan 13, 2010, at 1:40 PM, Michael M Slusarz wrote:
>
>> Quoting Ben Klang <ben at alkaloid.net>:
>>
>>> As long as we're talking only about local branches, I think we are  
>>> all in agreement.  The above instructions work great, and it's  
>>> what I do for local branches.
>>>
>>> My concern comes from multiple developers working on remote  
>>> branches, in this case the branch remote living on dev.horde.org.   
>>> I agree with what you said above that "I want my topic branches to  
>>> only contain the differences to master."  My question is how to go  
>>> about doing that with a remote tracking branch.  In my  
>>> experimentation so far, I've found that performing a rebase to  
>>> master on a remote-tracking branch makes me unable to push the  
>>> branch back upstream.  The only way I've found to update my  
>>> remote-tracking branch has been to merge from master, but  
>>> obviously that leaves me with a messy history.
>>
>> I will echo Mike R.'s statement that this has never been an issue  
>> for me.  You should be able to push whatever you want to a branch,  
>> as long as your local branch is up-to-date.  If it's not working  
>> properly, there may be something wonky with your local repo.
>>
>> michael
> I can re-create the problem pretty easily, so it's probably a  
> user-education problem.  Here's what I did:
>
> 1) Create a local branch ("TestBranch") and push it up to the remote  
> server.  (To be sure my local branch is tracking the remote branch I  
> deleted the original branch and then explicitly told it to checkout  
> a copy of the remote-tracking branch).
>
> 2) Make some changes to my checkout of the remote-tracking branch  
> and commit them.  My local (remote-tracking) branch is now one  
> commit ahead of upstream.
>
> 3) Something gets committed to origin/master.
>
> 4) "git fetch" to pull in the changes.
This should be `git pull --rebase` (while on master branch)


>
> 5) "git rebase origin/master" to roll forward the changes to my  
> local branch.  This completes successfully.
>
> 6) "git push" to send my now-rebased local branch changes up to the  
> server.  Here's where my problem begins.

You are skipping the additional rebase that must be performed on your  
topic branch against the remote. You need another git pull --rebase  
(while on your topic branch)

   Git reports:
> $ git push
> To /Users/bklang/src/horde
>  ! [rejected]        TestBranch -> TestBranch (non-fast-forward)
> error: failed to push some refs to '/Users/bklang/src/horde'
> To prevent you from losing history, non-fast-forward updates were rejected
> Merge the remote changes before pushing again.  See the 'non-fast-forward'
> section of 'git push --help' for details.
>
> "git status" now says this:
> $ git status
> # On branch TestBranch
> # Your branch and 'origin/TestBranch' have diverged,
> # and have 20 and 1 different commit(s) each, respectively.
> #
> nothing to commit (working directory clean)
>
> I can do a "git pull --rebase" but now I've got changesets from  
> "master" in my local branch:
> $ git status
> # On branch TestBranch
> # Your branch is ahead of 'origin/TestBranch' by 19 commits.

This is exactly what is expected, and what you need to do before  
pushing again to the remote topic branch. When the topic branch in  
merged INTO master, and then rebased, the duplicate commits will be  
detected and removed/ignored.

Thanks,
mike

--
The Horde Project (www.horde.org)
mrubinsk at horde.org

"Time just hates me. That's why it made me an adult." - Josh Joplin


More information about the dev mailing list