threads / discuss / 20375

Merging to and from non-current branches.

Subject: Merging to and from non-current branches.

## tl;dr

11 messages between Aug 4, 2009 and Aug 6, 2009.

replies: 10people: 8as markdown or json

lists@mgreg.com· Aug 4, 2009, 23:21 UTC · lore
Hi All,

I've been reading up on some of the GIT commands and I'm not sure if what I want/need exists. Basically I want to merge all changes from one branch to another, regardless of whether I'm in either of those branches. At the very least I would like to merge an existing "development" branch with the "master" branch without needing to first check out master. I've seen rebase, but I'm not absolutely sure what that's doing. Thoughts?

Best, Michael

Daniel Barkalow· Aug 5, 2009, 02:45 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

On Tue, 4 Aug 2009, lists@mgreg.com wrote:
Show 8 quoted lines
> Hi All,
> 
> I've been reading up on some of the GIT commands and I'm not sure if what I
> want/need exists.  Basically I want to merge all changes from one branch to
> another, regardless of whether I'm in either of those branches.  At the very
> least I would like to merge an existing "development" branch with the "master"
> branch without needing to first check out master.  I've seen rebase, but I'm
> not absolutely sure what that's doing.  Thoughts?

It can't work, because you need to be able to use the working tree to resolve any conflicts that arise during the merge. Merging without checking out a branch is a bit like building without checking out a branch; it would be avoiding using the filesystem for what it's there for.

	-Daniel
*This .sig left intentionally blank*
lists@mgreg.com· Aug 5, 2009, 02:48 UTC · re: Daniel Barkalow · lore

Re: Merging to and from non-current branches.

On Aug 4, 2009, at 10:45 PM, Daniel Barkalow wrote:
Show 25 quoted lines
> On Tue, 4 Aug 2009, lists@mgreg.com wrote:
>
>> Hi All,
>>
>> I've been reading up on some of the GIT commands and I'm not sure  
>> if what I
>> want/need exists.  Basically I want to merge all changes from one  
>> branch to
>> another, regardless of whether I'm in either of those branches.  At  
>> the very
>> least I would like to merge an existing "development" branch with  
>> the "master"
>> branch without needing to first check out master.  I've seen  
>> rebase, but I'm
>> not absolutely sure what that's doing.  Thoughts?
>
> It can't work, because you need to be able to use the working tree to
> resolve any conflicts that arise during the merge. Merging without
> checking out a branch is a bit like building without checking out a
> branch; it would be avoiding using the filesystem for what it's  
> there for.
>
> 	-Daniel
> *This .sig left intentionally blank*
>
Hi Daniel,

I appreciate your post. I understand what you're saying, and I'm not so much concerned about the logistics of what need to occur so much as a single command to intuitively handle it. I've been doing a great deal of incremental development lately and it becomes rather tedious to have to checkout master, merge dev, re-checkout dev and proceed. I'm not sure why this isn't currently possible with a single command. I suppose I could write a shell script to do so, but that's a little less "native" than I'd like.

Best,
Michael
Adam Brewster· Aug 5, 2009, 03:33 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

In case it helps, I think that if you're on branch dev, and you `merge master`, you should get a commit that's substantially similar to that that you'd get if you're on master and you `merge dev`.

The most noticeable difference should be that if you `checkout master && merge dev` the master is updated to point to the merged commit, whereas if you `checkout dev && merge master` dev is updated to the new commit.

(If there are conflicts, then the merge processes will differ more significantly, but hopefully the human should be able to sort that out.)

You should be able to use git-reset and git update-ref to clean up the mess if that's not good enough.

Adam Brewster
On Tue, Aug 4, 2009 at 10:48 PM, lists@mgreg.com<lists@mgreg.com> wrote:
Show 48 quoted lines
>
> On Aug 4, 2009, at 10:45 PM, Daniel Barkalow wrote:
>
>> On Tue, 4 Aug 2009, lists@mgreg.com wrote:
>>
>>> Hi All,
>>>
>>> I've been reading up on some of the GIT commands and I'm not sure if what
>>> I
>>> want/need exists.  Basically I want to merge all changes from one branch
>>> to
>>> another, regardless of whether I'm in either of those branches.  At the
>>> very
>>> least I would like to merge an existing "development" branch with the
>>> "master"
>>> branch without needing to first check out master.  I've seen rebase, but
>>> I'm
>>> not absolutely sure what that's doing.  Thoughts?
>>
>> It can't work, because you need to be able to use the working tree to
>> resolve any conflicts that arise during the merge. Merging without
>> checking out a branch is a bit like building without checking out a
>> branch; it would be avoiding using the filesystem for what it's there for.
>>
>>        -Daniel
>> *This .sig left intentionally blank*
>>
>
>
> Hi Daniel,
>
> I appreciate your post.  I understand what you're saying, and I'm not so
> much concerned about the logistics of what need to occur so much as a single
> command to intuitively handle it.  I've been doing a great deal of
> incremental development lately and it becomes rather tedious to have to
> checkout master, merge dev, re-checkout dev and proceed.  I'm not sure why
> this isn't currently possible with a single command.  I suppose I could
> write a shell script to do so, but that's a little less "native" than I'd
> like.
>
> Best,
>
> Michael
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Sverre Rabbelier· Aug 5, 2009, 03:46 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

Heya,
On Tue, Aug 4, 2009 at 19:48, lists@mgreg.com<lists@mgreg.com> wrote:
Show 8 quoted lines
> I appreciate your post.  I understand what you're saying, and I'm not so
> much concerned about the logistics of what need to occur so much as a single
> command to intuitively handle it.  I've been doing a great deal of
> incremental development lately and it becomes rather tedious to have to
> checkout master, merge dev, re-checkout dev and proceed.  I'm not sure why
> this isn't currently possible with a single command.  I suppose I could
> write a shell script to do so, but that's a little less "native" than I'd
> like.
You might want to try out an alias:

$ git config alias.update "!git checkout master && git merge dev && git checkout dev"

-- 
Cheers,

Sverre Rabbelier
Alex Riesen· Aug 5, 2009, 21:28 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

On Wed, Aug 5, 2009 at 04:48, lists@mgreg.com<lists@mgreg.com> wrote:
Show 6 quoted lines
> I appreciate your post.  I understand what you're saying, and I'm not so
> much concerned about the logistics of what need to occur so much as a single
> command to intuitively handle it.  I've been doing a great deal of
> incremental development lately and it becomes rather tedious to have to
> checkout master, merge dev, re-checkout dev and proceed.  I'm not sure why
> this isn't currently possible with a single command.
Because no one needed this sequence of commands for long enough.
> I suppose I could write a shell script to do so, but that's a little less "native"
> than I'd like.

But that's absolutely native to Git. Many Git commands are just shell scripts! Many guarantee (the "plumbing") you stability and machine-readability of their output precisely for this reason.

Write your script, propose it here, and there will be enough interest it'll land in the official distribution (or, more likely, in the "contrib" directory of it).

lists@mgreg.com· Aug 6, 2009, 01:48 UTC · re: Alex Riesen · lore

Re: Merging to and from non-current branches.

On Aug 5, 2009, at 5:28 PM, Alex Riesen wrote:
Show 13 quoted lines
> On Wed, Aug 5, 2009 at 04:48, lists@mgreg.com<lists@mgreg.com> wrote:
>> I appreciate your post.  I understand what you're saying, and I'm  
>> not so
>> much concerned about the logistics of what need to occur so much as  
>> a single
>> command to intuitively handle it.  I've been doing a great deal of
>> incremental development lately and it becomes rather tedious to  
>> have to
>> checkout master, merge dev, re-checkout dev and proceed.  I'm not  
>> sure why
>> this isn't currently possible with a single command.
>
> Because no one needed this sequence of commands for long enough.

As I said, I understand what is being said, but in IMHO it would seem that a merge of that nature would be immediately desirable. Think of it more as a local "push". I'm never a fan of "because it hasn't be done means it shouldn't be". I realize that's not exactly what you're saying though. Anyway, I absolutely appreciate the post, and may very well post the script.

Best,
Michael
Randal L. Schwartz· Aug 6, 2009, 02:15 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

>>>>> "mgreg" == lists@mgreg com <lists@mgreg.com> writes:

mgreg> As I said, I understand what is being said, but in IMHO it would seem mgreg> that a merge of that nature would be immediately desirable. Think of mgreg> it more as a local "push". I'm never a fan of "because it hasn't be mgreg> done means it shouldn't be". I realize that's not exactly what you're mgreg> saying though. Anyway, I absolutely appreciate the post, and may very mgreg> well post the script.

In other words, you'd be happy with it if it was just a fast-forward only?

Because the moment you might have conflicts, that *has* to be the workdir so you can resolve those conflicts. Dunno why this is so hard to grok.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
Daniel Barkalow· Aug 6, 2009, 17:41 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

On Wed, 5 Aug 2009, lists@mgreg.com wrote:
Show 17 quoted lines
> 
> On Aug 5, 2009, at 5:28 PM, Alex Riesen wrote:
> 
> >On Wed, Aug 5, 2009 at 04:48, lists@mgreg.com<lists@mgreg.com> wrote:
> > >I appreciate your post.  I understand what you're saying, and I'm not so
> > >much concerned about the logistics of what need to occur so much as a
> > >single
> > >command to intuitively handle it.  I've been doing a great deal of
> > >incremental development lately and it becomes rather tedious to have to
> > >checkout master, merge dev, re-checkout dev and proceed.  I'm not sure why
> > >this isn't currently possible with a single command.
> >
> >Because no one needed this sequence of commands for long enough.
> 
> As I said, I understand what is being said, but in IMHO it would seem that a
> merge of that nature would be immediately desirable.  Think of it more as a
> local "push".

You mean like "git push . dev:master"? That does work in the case where a content merge is not required (although not otherwise).

	-Daniel
*This .sig left intentionally blank*
Junio C Hamano· Aug 6, 2009, 18:43 UTC · re: Daniel Barkalow · lore

Re: Merging to and from non-current branches.

Daniel Barkalow <barkalow@iabervon.org> writes:
Show 6 quoted lines
>> As I said, I understand what is being said, but in IMHO it would seem that a
>> merge of that nature would be immediately desirable.  Think of it more as a
>> local "push".
>
> You mean like "git push . dev:master"? That does work in the case where a 
> content merge is not required (although not otherwise).
Just to clarify.

It works _only_ when the push is a fast forward, i.e. where a merge is not required.

That is different from working in a case "where a content merge is not required".

The word "content merge" is often used in contrast to "tree level merge", meaning the latter can be finished by flipping stages inside the index by the three-way read-tree (--aggressive) while the former needs to call out to "merge-one-file".

But the push will be rejected if you need _any_ kind of merge.
Steffen Siebert· Aug 6, 2009, 11:54 UTC · re: lists@mgreg.com · lore

Re: Merging to and from non-current branches.

lists <at> mgreg.com <lists <at> mgreg.com> writes:
Show 6 quoted lines
> a single command to intuitively handle it.  I've been doing a great  
> deal of incremental development lately and it becomes rather tedious  
> to have to checkout master, merge dev, re-checkout dev and proceed.   
> I'm not sure why this isn't currently possible with a single command.   
> I suppose I could write a shell script to do so, but that's a little  
> less "native" than I'd like.
Hi Michael,

I had a similar problem (we are doing rebases instead of merges) and found a way to rebase and push my changes onto the master without the need of a "checkout master".

You can find my question and the approved (green) answer that works for me on stackoverflow.com:

http://stackoverflow.com/questions/945372/how-to-efficiently-rebase-and-push-a-local-git-branch
Maybe this works for you, too.
Ciao,
  Steffen

← back to recent threads