Shared Repositories Should Be Bare Repositories

在创建中央仓库供其他用户共享时,应使用git init --bare选项创建裸仓库。裸仓库不包含工作目录和.git目录,仅包含.git目录中通常包含的文件。这样可以避免在非共享仓库中出现的工作目录和.git目录的变动导致的状态不一致问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shared Repositories Should Be Bare Repositories

Commands discussed in this section:

  • git init –bare

Shared Repositories Should Be Bare Repositores

When creating a central repository that will be shared by other users, the repositories should be created with the –bareoption:

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 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.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!

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 statusgit 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值