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

Mirroring repository state, with branches and submodules.

From
TWToby White <toby.o.h.white@googlemail.com>
Date
Mar 17, 2009, 15:21 UTC
Message-ID
<623D3837-E899-49AF-9A37-F667A311EE58@gmail.com>

I have a short script which does the following for a remote git rpository:

Clones it (checking out a working tree) Makes tracking local branches for all remote branches Init/updates all submodules.

This gives me an up-to-date mirror of a remote repository. I treat this as essentially read-only.

What I now want to do is have some command which will update this local mirror to reflect exactly the state of the remote mirror; even when the remote mirror may have rebased history.

So far, I'm doing the following:
git fetch
for BRANCH in $(git branch -r | cut -d / -f 2); do
   git checkout $BRANCH
   git reset --hard origin/$BRANCH
done
git submodule update --init

but I'm not sure if that's actually the right way to do it, or if I'm missing any corner cases. Am I safe to use it?

Thanks, Toby

Next: Miklos Vajna
Message 1 of 2 in “Mirroring repository state, with branches and submodules.”
  1. Toby WhiteMar 17, 2009
  2. Miklos VajnaMar 17, 2009

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.