Repositories in Git are a snapshot of the folder in which you are working on your project. You can track the progress and changes made to the project by making commits and also revert changes if not satisfactory.
Repositories can be divided into two types based on the usage on a server. These are:
- Non-bare Repositories
- Bare Repositories
1. Non-bare Repository (Default Repository)
A non-bare repository is the standard Git repository you get when you run git init in a project folder. It contains:
- A
.gitfolder (stores all information about commits, branches, and history) - Your project files (working tree)
File structure of a non-bare repository:
-- Default_Repo*
|-- .git*
| |-- hooks*
| |-- info*
| |-- logs*
| |-- objects*
| |-- refs*
| |-- COMMIT_EDITMSG
| |-- config
| |-- description
| |-- HEAD
| |-- index
|-- example.txt
*: Folders
Key Points:
- Used for local development
- You can edit, commit, and track changes
.gitfolder is the âbrainâ of your repository
2. Bare Repository
A bare repository is different because it does not have a working tree, meaning you cannot directly modify or commit files inside it. It contains only the .git folder contents.
Why does it exist?
- Serves as a central repository for collaboration
- Acts as a âreferenceâ for other developers to clone, push, or pull changes
- Prevents conflicts in shared development environments
Creating a Bare Repository:
>mkdir FileName.git >cd FileName.git >git init âbare
File structure of a bare repository:
-- BareRepo.git*
|-- hooks*
|-- info*
|-- logs*
|-- objects*
|-- refs*
|-- COMMIT_EDITMSG
|-- config
|-- description
|-- HEAD
|-- index
*: Folders
Key Points:
- Has the same structure as
.gitfolder in non-bare repo. - Always named with
.gitextension (e.g.,BareRepo.git). - Cannot commit changes directly.
- Only operations: push or clone.
3. Using a Bare Repository
Step 1: Clone a bare repository
Create a local repository by cloning the bare repository:
cd C:/Users/example/repositories
git clone C:/Users/example/BareRepo.git
Output might show a warning:
warning: You appear to have cloned an empty repository.Step 2: Add files and commit locally
cd BareRepo
git add *
git commit -m "First commit"
Step 3: Push changes to the bare repository
git push C:/Users/example/BareRepo.gitNow, your local repository is linked to the bare repository.
4. Converting a Local Repository to Bare
If you already have a local repository, you can clone it as bare:
cd "Central Repositories"
git clone --bare ../../path_to_local_repo
This creates LocalRepo.git as a bare repository.
5. Why Only Bare Repositories Are Used as Central Repositories
Git does not allow pushing to a non-bare repository by default.
- If you try, youâll get an error like:
remote: error: refusing to update checked out branch: refs/heads/masterYou can bypass it by changing settings (receive .deny Current Branch ignore), but this can create inconsistencies between the working tree and commits.
Key Reasons to use Bare Repositories as Central Repositories:
- Avoids conflicts between multiple developers
- Prevents inconsistent working tree
- Efficient storage (only tracks
.gitcontents) - Recommended for remote servers
Non-bare Repository (Local) Vs Bare Repository (Central/Remote)
| Feature | Non-bare Repository (Local) | Bare Repository (Central/Remote) |
|---|---|---|
| Working Tree | Yes | No |
| Commit Files Directly | Yes | No |
| Purpose / Use | Local development | Central repository / collaboration |
| File Structure | .git + project files | Only .git contents |
| Push / Pull | Pull from remote, push to bare | Accepts push and allows clone only |


