{"thread":{"id":"18348","subject":"Mirroring repository state, with branches and submodules.","startedAt":"2009-03-17T15:21:40Z","lastAt":"2009-03-17T16:56:35Z","messageCount":2,"participants":["Toby White","Miklos Vajna"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"108235","messageId":"623D3837-E899-49AF-9A37-F667A311EE58@gmail.com","threadId":"18348","inReplyTo":null,"subject":"Mirroring repository state, with branches and submodules.","fromName":"Toby White","fromEmail":"toby.o.h.white@googlemail.com","sentAt":"2009-03-17T15:21:40Z","receivedAt":"2009-03-17T15:21:40Z","isPatch":false,"sender":{"key":"toby.o.h.white@googlemail.com","avatar":null},"body":"I have a short script which does the following for a remote git  \nrpository:\n\nClones it (checking out a working tree)\nMakes tracking local branches for all remote branches\nInit/updates all submodules.\n\nThis gives me an up-to-date mirror of a remote repository. I treat  \nthis as essentially read-only.\n\nWhat I now want to do is have some command which will update this  \nlocal mirror to reflect exactly the state of the remote mirror;\neven when the remote mirror may have rebased history.\n\nSo far, I'm doing the following:\n\ngit fetch\nfor BRANCH in $(git branch -r | cut -d / -f 2); do\n   git checkout $BRANCH\n   git reset --hard origin/$BRANCH\ndone\ngit submodule update --init\n\nbut I'm not sure if that's actually the right way to do it, or if I'm  \nmissing any corner cases. Am I safe to use it?\n\nThanks,\nToby\n"},{"id":"108262","messageId":"20090317165635.GB3817@genesis.frugalware.org","threadId":"18348","inReplyTo":"623D3837-E899-49AF-9A37-F667A311EE58@gmail.com","subject":"Re: Mirroring repository state, with branches and submodules.","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2009-03-17T16:56:35Z","receivedAt":"2009-03-17T16:56:35Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Tue, Mar 17, 2009 at 03:21:40PM +0000, Toby White <toby.o.h.white@googlemail.com> wrote:\n> git fetch\n> for BRANCH in $(git branch -r | cut -d / -f 2); do\n>    git checkout $BRANCH\n>    git reset --hard origin/$BRANCH\n> done\n> git submodule update --init\n\nFirst, I think you don't handle the case when you have multiple\nremotes. I don't know if this is a problem for you or not.\n\nSecond, use plumbing in scripts, git for-each-ref has a stable output\nformat, while git branch may change.\n"}]}