git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Updating not actual branch

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2013, 16:03 UTC
Message-ID
<7v620w8v1v.fsf@alter.siamese.dyndns.org>
In-Reply-To
<006501ce1f24$94636a30$bd2a3e90$@certicon.cz>
Jan Pešta <jan.pesta@certicon.cz> writes:
Show 16 quoted lines
> I have following situation:
>
> A - B - C - I - J                       master
>                \ - D - E - F               feature 1
>                                  \ G - H     feature 2 (working copy)
>
> I would like tu update whole tree with latest changes in master
>
> A - B - C - I - J                                              master
>                            \ - D* - E* - F*                  feature 1
>                                                    \ G* - H*     feature 2
> (working copy)
>
>
> Is there some way how to do it without swithing to each branch and update
> them manually?

With these asterisks I would assume that you are rebasing feature #n on top of updated master. As rebasing requires you to have a working tree, so that you can resolve potential conflicts between your work and work done on the updated upstream, you fundamentally would need to check out the branch you work on.

In the case you depicted where feature-1 is a complete subset of feature-2, you are rebasing both of them, and you do not end up in a nasty conflict, you could start from this state:

    A---B---C master
             \
              D---E---F feature-1
                       \
                        G---H feature-2
update the master from the upstream:
    $ git checkout master ; git pull
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H feature-2
rebase feature-2 on top of the updated master:
    $ git rebase master feature-2
                                G'--H' feature-2
                               /
                      D'--E'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H
and finally repoint feature-1 to its updated version:
    $ git branch -f feature-1 F'
                                G'--H' feature-2
                               /
                      D'--E'--F' feature-1
                     /
    A---B---C---I---J master
             \
              D---E---F
                       \
                        G---H

Depending on the interaction between commits C..J and C..F, your rebasing of feature-2 may end up not losing any of D', E' or F'. Imagine the case where J was committed on the upstream by applying the same patch as the original E; E' will become redundant and the result of your "git rebase master feature-2" may look like this instead:

                            G'--H' feature-2
                           /
                      D'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H

Or J could remove something E depends on, in which case you may have to add it back with a new commit X when you rebase feature-2, like so:

                                    G'--H' feature-2
                                   /
                      D'--X---E'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H

Because you cannot mechanically decide where the tip of updated feature-1 has to be, you would need to use your brain to decide where to repoint the tip of feature-1 in the last step.

Previous: Konstantin Khomoutov
Message 3 of 3 in “Updating not actual branch”
  1. Jan PeštaMar 12, 2013
  2. Konstantin KhomoutovMar 12, 2013
  3. Junio C HamanoMar 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.