在我自己的服务器上托管私有 Git 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4626079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hosting Private Git repos on my own server?
提问by Stoic
I am looking for a way to host private git repos on my own server.
I am using Github for Open source projects of mine, but I would prefer to use my own server for storing private git repos.
我正在寻找一种在我自己的服务器上托管私有 git 存储库的方法。
我将 Github 用于我的开源项目,但我更喜欢使用我自己的服务器来存储私有 git 存储库。
Can someone suggest me on which script should I be using for this purpose.
Trac is not what I am looking for, though. I want something that is, preferably PHP based solution (just optional) and esp. something that has an easier UI.
有人可以建议我为此目的使用哪个脚本。
不过,Trac 不是我要找的东西。我想要的东西,最好是基于 PHP 的解决方案(只是可选的)和 esp。具有更简单用户界面的东西。
Any help is appreciated here.
任何帮助在这里表示赞赏。
采纳答案by Stoic
Well, for non-gitosis/gitorious setup you have two options really:
好吧,对于非 gitosis/gitorious 设置,您实际上有两个选择:
- Give people linux accounts with full shells (passwords and/or ssh keys) to have access to the git repository.
- Give people access to a linux account via their ssh key being in
/home/ac/.ssh/authorized_keys2
whose shell is set to/usr/bin/git-shell
. This means they won't be able to log in as a linux user with a shell and so do anything except use git on your machine.
- 为人们提供具有完整 shell(密码和/或 ssh 密钥)的 linux 帐户以访问 git 存储库。
- 允许人们通过
/home/ac/.ssh/authorized_keys2
其 shell 设置为/usr/bin/git-shell
. 这意味着他们将无法使用 shell 以 linux 用户身份登录,因此除了在您的机器上使用 git 之外,可以做任何事情。
In both cases, the user in question needs (read|write|both) access to the git repository, according to your needs, either as a user or as part of a group.
在这两种情况下,根据您的需要,相关用户需要(读|写|两者)访问 git 存储库,无论是作为用户还是作为组的一部分。
It might make sense for you to have a directory /git/project and then have user repositories in there, as having multiple people pushing to the same repository is generally a bad idea (people break things too easily in my experience). For example, you might have /srv/git/proj/proj-ninefingers.git
and have a "release" repo of '/srv/git/proj/project.git` That's probably what I'd do if running a team effort. Permissions, shells etc to be set as appropriate.
对您来说,拥有一个目录 /git/project 然后在其中拥有用户存储库可能是有意义的,因为让多个人推送到同一个存储库通常是一个坏主意(根据我的经验,人们很容易破坏事物)。例如,您可能拥有/srv/git/proj/proj-ninefingers.git
并拥有“/srv/git/proj/project.git”的“发布”存储库。如果运行团队合作,这可能是我会做的。权限、shell 等要适当设置。
Note that if you want to allow exports via the read-only git protocol you need to ensure the configured git user has read access and that git-daemon-export-ok
exists in your bare repository. git update-server-info
must also be run before gitweb
will pick up the repository, should you wish to use that.
请注意,如果您想允许通过只读 git 协议导出,您需要确保配置的 git 用户具有读取访问权限并且git-daemon-export-ok
存在于您的裸存储库中。如果您希望使用它,git update-server-info
也必须在gitweb
选择存储库之前运行。
As others have said, git gc
optimises the repository and it is a good idea to do this regularly. Cron job?
正如其他人所说,git gc
优化存储库,定期执行此操作是个好主意。定时任务?
Finally, a plethora of frameworks exist to simplify this (gitosis, gitorious, ...). I don't think it gets any simpler than providing access to a folder via various mechanisms but then that's me.
最后,存在大量框架来简化这一点(gitosis、gitorious 等)。我不认为它比通过各种机制提供对文件夹的访问更简单,但这就是我。
As an example of my setup, it being only me, I have:
作为我的设置的一个例子,只有我,我有:
$ cat /etc/passwd | grep git
git:x:1002:1002:Antony Vennard,,,:/home/git:/usr/bin/git-shell
gitdaemon:x:112:65534::/nonexistent:/bin/false
$ cat /etc/group | grep git
git:x:1002:
$ ls -l /srv/git
drwxr-xr-x 7 git git 4096 2010-09-12 23:31 bsdnt.git
drwxr-xr-x 7 git git 4096 2010-06-16 22:32 vforth.git
$ cat /home/git/.ssh/authorized_keys2
ssh-rsa somehex user1
ssh-rsa somehex user2
This means anyone with the private key user1 can log in and commit to either of those repositories.
这意味着任何拥有私钥 user1 的人都可以登录并提交到这些存储库中的任何一个。
回答by miku
Never tried it myself, but gitorious hosts the code their running on:
我自己从来没有尝试过,但是 gitorious 托管了他们运行的代码:
Another option with gitosis:
gitosis 的另一种选择:
回答by Jan Liesendahl
回答by Simon Richter
If you want just the code repository and no web pages, just place the ".git" directory somewhere accessible, that is sufficient for cloning via HTTP (note that you will need ssh or similar to push to that repository).
如果您只需要代码存储库而不需要网页,只需将“.git”目录放在可访问的地方,这足以通过 HTTP 进行克隆(请注意,您将需要 ssh 或类似工具才能推送到该存储库)。
For example, a project of mine is hosted this way at http://psi5.com/~geier/mutextrace.git.
例如,我的一个项目以这种方式托管在http://psi5.com/~geier/mutextrace.git。
It is a good idea to periodically run "git gc" on that repository in order to pack objects together, so clients don't have to make thousands of accesses.
定期在该存储库上运行“git gc”以将对象打包在一起是一个好主意,因此客户端不必进行数千次访问。
If you want web pages, then gitorious is indeed the way to go.
如果你想要网页,那么 gitorious 确实是要走的路。