Open In App

Bare Repositories in Git

Last Updated : 30 Sep, 2025
Comments
Improve
Suggest changes
4 Likes
Like
Report

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 .git folder (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
  • .git folder 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 .git folder in non-bare repo.
  • Always named with .git extension (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.git

Now, 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/master

You 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 .git contents)
  • Recommended for remote servers

Non-bare Repository (Local) Vs Bare Repository (Central/Remote)

FeatureNon-bare Repository (Local)Bare Repository (Central/Remote)
Working TreeYesNo
Commit Files DirectlyYesNo
Purpose / UseLocal developmentCentral repository / collaboration
File Structure.git + project filesOnly .git contents
Push / PullPull from remote, push to bareAccepts push and allows clone only
Suggested Quiz
5 Questions

What is the main difference between a non-bare repository and a bare repository?

  • A

    A bare repository contains both .git data and working files

  • B

    A non-bare repository does not have a .git folder

  • C

    A non-bare repository includes a working tree, while a bare repository does not

  • D

    A bare repository allows direct editing of project files

Explanation:

A non-bare repository has both the .git folder and the working tree (actual project files). A bare repository contains only the .git data and no working tree, meaning you cannot directly edit or commit files inside it. Bare repositories act as central servers for collaboration.

Why are bare repositories used as central repositories in Git?

  • A

    They allow developers to edit files directly

  • B

    Git does not allow pushing to non-bare repositories by default

  • C

    They store more history than non-bare repositories

  • D

    They automatically merge all branches

Explanation:

Git prevents pushing to a non-bare repository because it may have an active working tree, leading to inconsistencies. Bare repositories avoid such conflicts because they contain no working files. Therefore, they are the recommended choice for central servers.

Which of the following operations can be performed directly inside a bare repository?

  • A

    Editing project files

  • B

    Committing new code

  • C

    Pushing from local repos or cloning

  • D

    Creating a working tree

Explanation:

Bare repositories cannot be used for editing, staging, or committing, since there is no working tree. They only accept Git operations like push, pull, and clone, which makes them ideal for centralized collaboration.

What command is used to create a bare version of an existing local repository?

  • A

    git init --new

  • B

    git convert --bare

  • C

    git clone --bare

  • D

    git init --remote

Explanation:

Using git clone --bare converts a local repository into a bare version. This creates a new repository that contains only .git contents and is typically named with a .git extension, such as MyRepo.git.

What happens if multiple developers push to a non-bare repository with a working tree?

  • A

    Git automatically resolves conflicts

  • B

    It works normally with no issues

  • C

    The working tree may become inconsistent, causing errors

  • D

    The repository becomes read-only

Explanation:

A non-bare repository has an active working tree, so allowing pushes can lead to inconsistent states, overwriting files that are currently checked out. Git prevents this to ensure safety, which is why only bare repositories should be used as shared central repositories.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Article Tags :

Explore