As you probably know, the
git init command is used to create a new Git repository. It initializes a new repository by creating an initial file and folder structure that is required for a Git repository to work and track changes in your project.
When running the
git init command you can use the
Without the bare option
If you are not using the
bare option, then these files will be placed in a
.git named directory in the root of your project directory. In this case, your project directory will contain the current working files of your project alongside with the
.git that contains all of the version tracking information. Most commonly this is the way you want to set up your repository because it allows you to work on your project and then commit your changes in your local repository.
With the bare option
git init --bare
If you use the bare option you will have all the files that would live in the
.git folder directly placed under the root of your project directory. So in this case there will be no working files, only the repository files that contain all the version history of your project. This means that you cannot directly commit to this repository, you can only push changes to this repo or pull changes from it. This is the purpose of a bare repository: to have a centralized server (even though git is a decentralized version control system), where you can share your changes with your teammates or with the world.
When you want to work on your project, make changes to it, you need to have all the working files at your disposal…because you want to work with them. So in this case you have to use a non-bare repository.
When you want to create a central repository where people working on the same project can share their changes with each other then you need to create a bare repository.