Home > other >  How to make git cloned mirrored repo not `mirror`?
How to make git cloned mirrored repo not `mirror`?

Time:12-16

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

CodePudding user response:

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.

CodePudding user response:

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)
  •  Tags:  
  • git
  • Related