How can I clone a git repository and keep remotes?

(This isn't a typical workflow, but I'll try to answer the direct question anyway...)

git push --mirror will indeed have pushed your remote-tracking branches to the same name on the remote. However, when you clone, you by default only get the refs under refs/heads, which are mapped to remote-tracking branches under refs/remotes/origin/. You could clone with git clone --mirror to get the remote-tracking branches from the remote as well, but that option implies --bare.

If you want a repository with a working tree whose branches are mirrored from the remote, you could always change the refspec in the config option remote.origin.fetch to fetch every ref to the same name, but again I suspect that the real problem is that you're using a very unusual workflow.

Incidentally, even if you use one of those techniques to change the mapping of the refs that are fetched, this won't clone the remotes themselves, which are defined in the repository's git config - git clone doesn't clone anything from .git/config, which is considered to contain private information.

Tags:

Git