{"thread":{"id":"33161","subject":"Updating not actual branch","startedAt":"2013-03-12T13:22:00Z","lastAt":"2013-03-12T16:03:24Z","messageCount":3,"participants":["Jan Pešta","Konstantin Khomoutov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"211130","messageId":"006501ce1f24$94636a30$bd2a3e90$@certicon.cz","threadId":"33161","inReplyTo":null,"subject":"Updating not actual branch","fromName":"Jan Pešta","fromEmail":"jan.pesta@certicon.cz","sentAt":"2013-03-12T13:22:00Z","receivedAt":"2013-03-12T13:22:00Z","isPatch":false,"sender":{"key":"jan.pesta@certicon.cz","avatar":"https://avatars.githubusercontent.com/u/5998957?v=4"},"body":"Hi All,\n\nI have a question if there is a posibility tu update a branch which is not\nactual working copy.\n\nI have following situation:\n\nA - B - C - I - J                       master\n               \\ - D - E - F               feature 1\n                                 \\ G - H     feature 2 (working copy)\n\nI would like tu update whole tree with latest changes in master\n\nA - B - C - I - J                                              master\n                           \\ - D* - E* - F*                  feature 1\n                                                   \\ G* - H*     feature 2\n(working copy)\n\n\nIs there some way how to do it without swithing to each branch and update\nthem manually?\n\nThanks,\nJan\n"},{"id":"211132","messageId":"20130312191936.d25cbca4934a8c92b7ec0542@domain007.com","threadId":"33161","inReplyTo":"006501ce1f24$94636a30$bd2a3e90$@certicon.cz","subject":"Re: Updating not actual branch","fromName":"Konstantin Khomoutov","fromEmail":"kostix+git@007spb.ru","sentAt":"2013-03-12T15:19:36Z","receivedAt":"2013-03-12T15:19:36Z","isPatch":false,"sender":{"key":"kostix+git@007spb.ru","avatar":null},"body":"On Tue, 12 Mar 2013 14:22:00 +0100\nJan Pešta <jan.pesta@certicon.cz> wrote:\n\n> I have a question if there is a posibility tu update a branch which\n> is not actual working copy.\n> \n> I have following situation:\n> \n> A - B - C - I - J                       master\n>                \\ - D - E - F               feature 1\n>                                  \\ G - H     feature 2 (working copy)\n> \n> I would like tu update whole tree with latest changes in master\n> \n> A - B - C - I - J                                              master\n>                            \\ - D* - E* - F*                  feature 1\n>                                                    \\ G* - H*\n> feature 2 (working copy)\n> \n> \n> Is there some way how to do it without swithing to each branch and\n> update them manually?\n\nIt's partially possible to do: you are able to forcibly fetch a remote\nobject into any local branch provided it's not checked out.  Hence, in\nyour case you'll be able to update any branch excapt for \"feature 2\".\n\nTo do this, you could use the explicit refspec when fetching, like this:\n\n$ git fetch origin +src1:dst1 '+blooper 1:feature 1'\n\n(Consult the `git fetch` manual for more info on using refspecs.)\n\nOne possible downside is that I'm not sure this approach would play\nnicely with remote branches, if you have any.  I mean, direct fetching\ninto local branches will unlikely to update their matching \"upstream\"\nremote branches.\n\nSo supposedly a better way to go would be to write a script which would\ngo like this:\n1) Do a simple one-argument `git fetch <remotename>` to fetch from\n   the specified remote and update its remote branches.\n2) Run `git for-each-ref`, and for each local branch found first check\n   whether it's currently checked out (that is, HEAD points at it)\n   and ignore the branch if it is; otherwise do `git update-ref`\n   updating the branch pointer from its upstream branch -- referring to\n   that using the <ref>@{upstream} syntax.\n   (Consult the gitrevisions manual for more info on this syntax.)\n"},{"id":"211138","messageId":"7v620w8v1v.fsf@alter.siamese.dyndns.org","threadId":"33161","inReplyTo":"006501ce1f24$94636a30$bd2a3e90$@certicon.cz","subject":"Re: Updating not actual branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-12T16:03:24Z","receivedAt":"2013-03-12T16:03:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jan Pešta <jan.pesta@certicon.cz> writes:\n\n> I have following situation:\n>\n> A - B - C - I - J                       master\n>                \\ - D - E - F               feature 1\n>                                  \\ G - H     feature 2 (working copy)\n>\n> I would like tu update whole tree with latest changes in master\n>\n> A - B - C - I - J                                              master\n>                            \\ - D* - E* - F*                  feature 1\n>                                                    \\ G* - H*     feature 2\n> (working copy)\n>\n>\n> Is there some way how to do it without swithing to each branch and update\n> them manually?\n\nWith these asterisks I would assume that you are rebasing feature #n\non top of updated master.  As rebasing requires you to have a\nworking tree, so that you can resolve potential conflicts between\nyour work and work done on the updated upstream, you fundamentally\nwould need to check out the branch you work on.\n\nIn the case you depicted where feature-1 is a complete subset of\nfeature-2, you are rebasing both of them, and you do not end up in\na nasty conflict, you could start from this state:\n\n    A---B---C master\n             \\\n              D---E---F feature-1\n                       \\\n                        G---H feature-2\n\nupdate the master from the upstream:\n\n    $ git checkout master ; git pull\n\n    A---B---C---I---J master\n             \\\n              D---E---F feature-1\n                       \\\n                        G---H feature-2\n\nrebase feature-2 on top of the updated master:\n\n    $ git rebase master feature-2\n\n                                G'--H' feature-2\n                               /\n                      D'--E'--F'\n                     /\n    A---B---C---I---J master\n             \\\n              D---E---F feature-1\n                       \\\n                        G---H\n\nand finally repoint feature-1 to its updated version:\n\n    $ git branch -f feature-1 F'\n\n                                G'--H' feature-2\n                               /\n                      D'--E'--F' feature-1\n                     /\n    A---B---C---I---J master\n             \\\n              D---E---F\n                       \\\n                        G---H\n\nDepending on the interaction between commits C..J and C..F, your\nrebasing of feature-2 may end up not losing any of D', E' or F'.\nImagine the case where J was committed on the upstream by applying\nthe same patch as the original E; E' will become redundant and the\nresult of your \"git rebase master feature-2\" may look like this\ninstead:\n\n                            G'--H' feature-2\n                           /\n                      D'--F'\n                     /\n    A---B---C---I---J master\n             \\\n              D---E---F feature-1\n                       \\\n                        G---H\n\nOr J could remove something E depends on, in which case you may have\nto add it back with a new commit X when you rebase feature-2, like\nso:\n\n                                    G'--H' feature-2\n                                   /\n                      D'--X---E'--F'\n                     /\n    A---B---C---I---J master\n             \\\n              D---E---F feature-1\n                       \\\n                        G---H\n\nBecause you cannot mechanically decide where the tip of updated\nfeature-1 has to be, you would need to use your brain to decide\nwhere to repoint the tip of feature-1 in the last step.\n"}]}