Shared Repositories Should Be Bare Repositories

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.

Recent Articles

What is the deal with the Git Index? What is the Git Index?

The git "index" is where you place files you want committed to the git repository. Learn more about the git index and git commit by selecting this link.

Visualising Branches And Their Commits | Git Show-branch

We explain and discuss the use of the git show-branch, gitg, gitk and qgit in this Tutorial. Complete with examples.

“Tracking Branches” And “Remote-Tracking Branches”

Both Tracking Branches and Remote Tracking Branches are created on the git client when a git clone command is used.

Temporarily Stashing Your Work

Git Stash is used when you want to record the current state of the working directory and index, without committing, to come back to complete later.

Shared Repositories Should Be Bare Repositories

Bare Repositories - When creating a central repository that will be shared by other users, the repositories should be created with the --bare option.

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox