What's the difference between git clone --mirror and git clone --bare
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
git clone --bare and git clone --mirror both create repositories without a working tree, which is why they are easy to confuse. The difference is that a bare clone changes the repository format, while a mirror clone is designed for full ref replication and future synchronization with the source repository.
What a Bare Clone Gives You
A bare repository contains only Git data and metadata. There is no checked-out working directory, so it is suitable for server-side remotes and repository storage.
After this command, project.git contains the repository objects, refs, and config, but not a directory of editable files. That is why bare repositories are commonly used as shared remotes for teams.
Use --bare when the repository’s role is simply "be a Git repository other people push to and fetch from." It is about layout, not about replication policy.
What --mirror Adds on Top
--mirror creates a bare repository too, but it also configures the clone as a mirror of the source.
The key word is mirror. Git copies and manages refs more aggressively so the destination is meant to match the source repository closely, including refs outside the usual local-branch-and-tag workflow.
That matters because Git refs are broader than just branches. A mirror is concerned with:
- branches
- tags
- remote-tracking refs
- notes
- other refs under
refs/
So --mirror is not merely "bare plus no working tree." It is "bare plus all-ref mirroring behavior."
Why the Ref Behavior Matters
A normal bare clone can still act as an ordinary remote repository with its own independent life. A mirror clone is intended to stay aligned with another repository.
That is why mirror clones are common in backup and migration workflows. For example:
Because the repository was configured for mirroring, ref updates are pulled in with mirror semantics rather than ordinary development defaults.
To replicate the repository to a second remote:
This command pushes all refs so the target becomes a close copy of the source repository state.
Choose Based on Repository Role
A helpful rule is to ask what job the clone will perform.
Choose --bare when you want:
- a central repository for collaborators
- a server-side remote with no working tree
- a clean repository-only storage format
Choose --mirror when you want:
- a backup repository
- a migration source or destination
- a replica that should track all refs from another repository
The commands look similar, but the intent is different. A collaboration remote is not the same thing as a mirror.
Example Scenarios
Suppose your team needs an internal Git remote on a server. A bare repository is enough because its job is simply to receive pushes and serve fetches.
Now suppose you are moving a repository between hosting providers, or keeping an internal backup that should preserve tags, unusual refs, and repository structure as faithfully as possible. That is a mirror scenario.
Using --mirror for a normal collaboration remote is often unnecessary and can be misleading because mirroring semantics imply a tighter "match the source exactly" contract than a team remote usually needs.
Common Pitfalls
The biggest mistake is assuming --mirror just means "copy everything a little more completely." It is really about replication behavior and ref mirroring, not just about cloning more data.
Another issue is expecting either kind of clone to have a working tree. Neither does. Both are repository-only layouts.
People also sometimes use a mirror clone as though it were an ordinary development remote without realizing that future mirror-style updates are designed to overwrite refs to match the source. That is appropriate for backup or migration, not always for collaborative workflows.
Finally, if all you need is a standard server-side repository, --bare is usually the simpler and more accurate tool.
Summary
- Both
--bareand--mirrorcreate repositories with no working tree. - '
--bareis mainly about repository layout for a remote-style repository.' - '
--mirroris about full ref replication and mirror-oriented synchronization.' - Use
--barefor ordinary shared remotes. - Use
--mirrorfor backups, migration, and true repository mirroring.
Related reading
- What's the difference between git diff --patience and git diff --histogram?
- What's the difference between 'git merge' and 'git rebase'?
- What''s the difference between git reset --mixed, --soft, and --hard?
- What''s the difference between git reset --mixed, --soft, and --hard?
- What's the difference between git reset and git checkout?
- What''s the difference between Git Revert, Checkout and Reset?
- What's the difference between 'git switch' and 'git checkout' <branch>?
- What's the difference between 'git switch' and 'git checkout' branch?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.