Commands discussed in this section:
- git init –bare
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.git Initialized 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 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.git gitadmin$ ls branches/ 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 master nothing 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!
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.
Git Remotes Example: Creating a Shared Repository; Users Sharing The Repository
Git Remotes Up Close: “Tracking Branches” and “Remote-Tracking Branches”
Git Remotes Up Close: The Configuration File – “remote” section
Git Remotes Up Close: The Configuration File – “branch” section
Git Remotes: Fun Commands You Can Use