2

I like a way to copy repo via clone --mirror as it copies all branches. However, it results in config that still AFAIK not ready for pull/push etc.:

[core]
    bare = true
[remote "origin"]
    fetch = +refs/*:refs/*
    mirror = true

Using --mirror posted e.g. here Move git repo with git clone --mirror and git push --mirror, I've tried to add

git remote set-url origin my-url (two tries: where target was - current, and new empty folder)
git push --mirror

But still same config, however in answers I have not found mentioning of similar issue.

Maybe it is so easy to fix it was omitted? How to make target to track repo the source is tracking? Just remove mirror = true and edit fetch = +refs/heads/*:refs/remotes/origin/* by hand? TIA

14
  • Sandboxes are cheap, just make another one. Mirrors are useful for some things, but it's best to make a regular clone for development work.
    – joanis
    Commented Dec 13, 2022 at 2:20
  • But, my real question is, why do you want to convert your mirror to a regular clone? Is there something important in this particular mirror you don't want to lose?
    – joanis
    Commented Dec 13, 2022 at 2:21
  • @joanis, I want to clone all local branches of remote. Maybe now there is a command in git to do that? IIRC people suggested scripts to loop all branches. Other solution was to use clone --mirror. Now I realized there is something important to be done after cloning. Commented Dec 13, 2022 at 2:23
  • When I do git clone <repo url>, I get all branches, so I'm not sure yet what you're trying to solve that a regular clone does not do.
    – joanis
    Commented Dec 13, 2022 at 2:24
  • By the way, short answer to the question as asked: while I'm sure it's possible to convert a mirror clone to a regular clone, it would be a fair amount of finicky work that would require a very good understanding of how Git stores information. That's a job for an advanced user, so it's best you find a different solution for what you're really trying to accomplish.
    – joanis
    Commented Dec 13, 2022 at 2:27

2 Answers 2

1

Posting an answer here to summarize the long chat:

In order to have all the branches downloaded locally for doing development (possibly) offline from a repo, you should use a regular clone rather than a mirror clone. It downloads all the remote-tracking branches from the remote, and Git can then create local branches from them whenever you need them.

A mirror clone is useful for other situations, like mirroring a whole repo (as the name says), uploading the mirror elsewhere, possibly backups, but not for use as a sandbox.

Converting between types would not be easy, it's best to make the right kind of clone in the first place.

Something I learned from the discussion: a mirror clone from GitHub (and possibly other Git servers with PRs or MRs) includes the refs to the PR head and merge commits, in packed_refs, while a regular clone does not include them.

2
  • Thanks again for the discussion. Later I recalled that w/out --mirror in cloned linux kernel repo one can see only current kerkel, , with --mirror repo gives also previous versions (accessed via tags). I have a guess now old commits were merged and deleted, only recent left, that is why previous kernel versions are not available w/out --mirror . Does above make sense? Commented Dec 14, 2022 at 5:38
  • 1
    @Martian2020 Not to me, no. Regular and mirror clones both include all the tags.
    – joanis
    Commented Dec 14, 2022 at 13:07
1

That answer is based on comment by @torek in Why line with "fetch" in git config effects how `git branch --set-upstream-to` work?

  1. change the fetch URL in .git/config from fetch = +refs/*:refs/* to fetch = +refs/heads/*:refs/remotes/origin/*
  2. git config --bool core.bare=false (or edit .git/config)
  3. create .git folder and move everything there (I usually do clone so that this step in not needed, via git clone --mirror "$1" "./.git")
  4. remove mirror=true line from .git/config (the line is initially in config, but it was not in @tokek comment and I don't know if it effects git work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.