Commands discussed in this section:
Shared Repositories Should Be Bare Repositories
When creating a central repository that will be shared by other users, the repositories should be created with the –bare option:
gitadmin$ git init --bare project1.gitInitialized empty Git repository in /home/gitadmin/project1.git/
When you create a git repository with the –bare option:
- There is no working directory created.
- There is no .git directory is created. Instead, the files normally in the .git directory are placed in the top-level directory where the working directory would normally be.
gitadmin$ cd project1.gitgitadmin$ lsbranches/ config description HEAD hooks/ info/ objects/ refs/
The Bare Git Repository
It is good that shared repositories don’t have working directories!
For example, imagine someone creating a non-bare git repository with both the git repository user and remote users updating the git object database.
The creator of the non-bare git repository would use the git status command one minute and see this:
$ git status# On branch masternothing to commit (working directory clean)
The next minute, a remote user could git push a change into the non-bare repository. Then when the creator of the non-bare git repository types git status, git would find a different object database and give different results for this run of git status.
The output of git status should not change unless the user has changed files in the working directory or their object database!
Share Via git clone/pull/fetch/pull
All users editing content from a shared directory need to share the repository via git clone/pull/fetch/push and not by sitting at the working directory and using git status, git add, and git commit, etc.
If the gitadmin user wants to edit files in the newly created repository, the gitadmin user would also need to use git clone (typed from a different directory) like the rest of the users of the shared repository.