9

This issue is not the same as git - how to mirror file from other repo or How do I update my bare repo?

Since a repository cloned with --mirror is a bare repository, can I make a repository cloned with --bare be like one cloned with --mirror? Can it be done by simply modifying the config file?

If not, is there other method which can convert a bare repository to a mirror repository?

Another question, Why can I not use git push --all in a mirror repo, while this command can be ran in a bare repo?

Community
  • 1
  • 1
thinke365
  • 1,265
  • 3
  • 14
  • 20
  • 2
    You can trivially edit the config file in any editor. Just make the branch references the way they are in a mirror repo (+refs/*:refs/*), remove the remote tracking branches (from packed-refs and refs/remote/*/*), add `mirror=true`, and re-run a `git fetch`. – fork0 Sep 10 '12 at 12:22
  • @fork0 this trivial operation seems not works... – thinke365 Sep 14 '12 at 19:49
  • exactly what does not work? Error messages? (BTW, I didn't mention in what section is `mirror=true` to be added. It is `[core]`). – fork0 Sep 15 '12 at 20:41

3 Answers3

14

To change a repository cloned with git clone --bare into one that matches what it would be with a git clone --mirror, do the following:

$ git config remote.origin.fetch "+refs/*:refs/*" 
$ git config remote.origin.mirror true

Then do a git fetch and everything should be up-to-date.

onionjake
  • 3,645
  • 25
  • 46
2

If you have clone your repo with git clone --mirror, then a git push --all, following the default matching push policy, will push all local branches to the remote repo.

But if your remote repo has been added to your local repo as a remote reference (ie your local repo has been cloned from another remote repo), then a git push --all secondRemoteRepo won't find many matching branch to push to, unless you fetch those branches first.
So this should work:

git fetch secondRemoteRepo
git push --all secondRemoteRepo
Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
1

Nowadays:

git remote add --mirror=fetch origin <url>

Then

git fetch
lbt
  • 706
  • 6
  • 10