When would you use git clone –bare over git clone –mirror?

Technology CommunityCategory: GitWhen would you use git clone –bare over git clone –mirror?
VietMX Staff asked 3 years ago

Suppose origin has a few branches (master (HEAD)nextpu, and maint), some tags (v1v2v3), some remote branches (devA/masterdevB/master), and some other refs (refs/foo/barrefs/foo/baz, which might be notes, stashes, other devs’ namespaces, who knows).

  • git clone --bare: You will get all of the tags copied, local branches master (HEAD)nextpu, and maint, no remote tracking branches. That is, all branches are copied as is, and it’s set up completely independent, with no expectation of fetching again. Any remote branches (in the cloned remote) and other refs are completely ignored.
  • git clone --mirror: Every last one of those refs will be copied as-is. You’ll get all the tags, local branches master (HEAD)nextpu, and maint, remote branches devA/master and devB/master, other refs refs/foo/bar and refs/foo/baz. Everything is exactly as it was in the cloned remote. Remote tracking is set up so that if you run git remote update all refs will be overwritten from origin, as if you’d just deleted the mirror and recloned it. As the docs originally said, it’s a mirror. It’s supposed to be a functionally identical copy, interchangeable with the original.

To summarize,

  • git clone --bare is used to make a copy of the remote repository with an omitted working directory.
  • git clone --mirror is used to clone all the extended refs of the remote repository, and maintain remote branch tracking configuration.