[dev] Fwd: Rebase vs. Merge

Ben Klang ben at alkaloid.net
Wed Jan 13 18:54:04 UTC 2010


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.  

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.  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 verified by viewing the repository in GitX and seeing duplicate commits from origin/master: 1 each in master and TestBranch.

So I must be doing something wrong, but I don't know what.

/BAK/

> 
> -- 
> ___________________________________
> Michael Slusarz [slusarz at horde.org]
> 
> 
> -- 
> Horde developers mailing list - Join the hunt: http://horde.org/bounties/
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: dev-unsubscribe at lists.horde.org

-- 
Ben Klang
Alkaloid Networks LLC
ben at alkaloid.net
404.475.4850
http://projects.alkaloid.net




More information about the dev mailing list