103

我有一个现有的 git repo(一个空的),到目前为止只有我可以写。我想向某个 UNIX 用户组 foo 开放它,以便 foo 的所有成员都可以推送到它。我知道我可以通过以下方式轻松设置的git 存储库:

git init --bare --shared=group repodir
chgrp -R foo repodir

但是我需要对现有的repo 目录进行等效的操作。

4

5 回答 5

125

尝试这样做以使现有存储库repodir为 group 中的用户工作foo

chgrp -R foo repodir                 # set the group
chmod -R g+rw repodir                # allow the group to read/write
chmod g+s `find repodir -type d`     # new files get group id of directory
git init --bare --shared=all repodir # sets some important variables in repodir/config ("core.sharedRepository=2" and "receive.denyNonFastforwards=true")
于 2010-07-13T23:34:10.717 回答
52

合并@David Underhill@kixorz 的答案,我制定了自己的(确定的)解决方案。

它适用于回购和非裸回购。它们之间只有很小的区别,但这样更清楚。

裸存储库

cd <repo.git>/                            # Enter inside the git repo
git config core.sharedRepository group    # Update the git's config
chgrp -R <group-name> .                   # Change files and directories' group
chmod -R g+w .                            # Change permissions
chmod g-w objects/pack/*                  # Git pack files should be immutable
find -type d -exec chmod g+s {} +         # New files get directory's group id

在哪里:

  • <repo.git>是裸存储库目录,通常在服务器上(例如my_project.git/)。
  • <group-name>是 git 用户的组名(例如users)。

非裸存储库

cd <project_dir>/                         # Enter inside the project directory
git config core.sharedRepository group    # Update the git's config
chgrp -R <group-name> .                   # Change files and directories' group
chmod -R g+w .                            # Change permissions
chmod g-w .git/objects/pack/*             # Git pack files should be immutable
find -type d -exec chmod g+s {} +         # New files get directory's group id

在哪里:

  • <project_dir>是包含文件夹的项目目录.git
  • <group-name>是 git 用户的组名(例如users)。
于 2015-04-15T09:10:41.897 回答
48

在 repo 目录中执行以下命令:

git config core.sharedRepository group
chgrp -R foo repodir
chmod -R g+w repodir

编辑:为了解决频繁的混淆,group是一个实际的关键字,你不应该用组的名称替换它。

于 2012-03-02T17:50:47.143 回答
3

这可能不是必需的,但值得指出的是,git init --bare --shared它还设置了denyNonFastForwards选项。

git config receive.denyNonFastForwards true

该选项的含义如下:

receive.denyNonFastForwards

如果您对已经推送的提交进行变基,然后再次尝试推送,或者尝试将提交推送到不包含远程分支当前指向的提交的远程分支,您将被拒绝。这通常是好的政策;但是在变基的情况下,您可以确定您知道自己在做什么,并且可以使用 -f 标志强制更新远程分支到您的推送命令。

(来自http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

于 2015-01-19T13:11:11.320 回答
1

除了上述允许组读/写的答案之外,您还需要将用户添加到组中(比如“foo”)。

sudo usermod -a -G [groupname] [username]

注意:如果用户不存在,则必须先创建用户

于 2016-04-18T18:31:29.107 回答