What's the -practical- difference between a Bare and non-Bare repository?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The practical difference is simple: a non-bare repository is where you do work, and a bare repository is usually where you exchange work. A non-bare repo has checked-out files you can edit. A bare repo has only Git's internal data and is commonly used as a shared remote target for pushes and pulls.
A non-bare repository has a working tree
This is the normal repository on a developer machine:
Inside it, you have:
- your checked-out files
- a
.gitdirectory containing history and metadata
You can open files, edit code, run tests, commit, branch, and so on. That is what most people mean when they say "a Git repo."
A bare repository has no working tree
A bare repository contains Git metadata directly at the top level and does not check out project files:
That repository is not meant for editing source files directly. Its job is usually to act as a central synchronization point, such as a server-side remote.
Because there is no checked-out working copy, there is no risk that a push will overwrite someone else's editable local files.
Why bare repositories are common on servers
When multiple developers push to a shared remote, Git wants that remote to behave like a pure repository store, not like a live working directory someone might also be editing. A bare repo is ideal for that because it contains:
- refs
- objects
- hooks
- configuration
but no checked-out branch files.
That is why remote URLs often end in .git. The suffix is conventional, and the repository is often bare.
Why pushing to a non-bare repository is awkward
If you push into a non-bare repository whose branch is checked out, Git has to worry about the working tree becoming inconsistent with the updated branch tip. That is why pushing to a normal checked-out repository is usually discouraged or blocked by default.
This is the practical rule:
- develop in non-bare repos
- publish or share through bare repos
That division keeps workflows clean.
You do not "work inside" a bare repo the same way
A bare repository can still be inspected with Git commands such as:
But you do not normally open files and edit them there. If you want to make changes, clone the bare repo into a non-bare working repository:
Then do your edits and commits in working-copy.
Think of them as different roles
A helpful mental model is:
- non-bare repo = workspace plus repository
- bare repo = repository only
That difference is structural, but the practical consequences are what matter:
- one is for editing
- one is for sharing
Common Pitfalls
- Treating a bare repository like a normal working directory.
- Hosting a shared central remote as a non-bare repo and then fighting checked-out-branch push issues.
- Assuming
.gitsuffix alone is what makes a repository bare. - Forgetting that a non-bare repo includes both the working tree and the Git database.
- Trying to edit files directly inside a bare repo instead of cloning it.
Summary
- A non-bare repository has a working tree and is used for normal development.
- A bare repository has only Git data and is usually used as a shared remote.
- Bare repos are safer push targets because they have no checked-out files to keep in sync.
- Non-bare repos are where you edit, test, and commit code.
- The practical difference is role: workspace versus exchange point.
Related reading
- What's the best visual merge tool for Git?
- What's the correct way to check if it's possible to perform a fast-forward merge with git merge-base?
- What's the difference between commit and apply in SharedPreferences
- What's the difference between git clone --mirror and git clone --bare
- 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?
.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.