这几天,刚好重新搭建了一个git server,其实曾经也搭建过的,这次把过程及遇到的问题简答记录一下吧。
Demoed on RHEL6.2 system
1. install rpm packages: git, git-daemon
2. prepare some git repos in /home/repo/pub
3. for a read-only repo
1 |
git daemon --verbose --export-all --base-path=/home/repo/pub --reuseaddr |
For a repo with ‘push’ operation allowed:
1 |
git daemon --verbose --export-all --base-path=/home/repo/pub –reuseaddr --enable=receive-pack |
另外可以使用,--detach 参数让git daemon以daemon方式运行在后台。
And need to add the following in XX.git/.git/config
1 2 3 |
[receive] denyCurrentBranch = ignore |
To expose repository:
You have to either put an empty file called git-daemon-export-ok into the repository or start git daemon with the “--export-all” option.
建好git server后,使用的话,直接 git clone git://server-ip/XX.git 即可。
允许push,也可以在server端设置如下:(或者如前面延时的git-daemon启动时添加“--enable=receive-pack”参数)
1 |
git config daemon.receivepack true |
描述了哪些用户/用户组对于分支/标签具有更新权限的配置文件:
$GIT_DIR/info/allowed_users
$GIT_DIR/info/allowed_groups
多数情况下,我们需要建立一个用户组(起名为 git ),并且将相关的开发者账户添加为该组成员。
在使用“git push origin mastrer”命令Push代码到数据仓库时,提示如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[remote rejected] master -> master (branch is currently checked out) remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsistent remote: error: with what you pushed, and will require 'git reset --hard' to match remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in some remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To git@192.168.1.X:/var/git.server/.../web ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web' |
这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:
1 2 |
[receive] denyCurrentBranch = ignore |
(当然如果是"git --bare init"命令来初始化建立的仓库,在server端不含有.git目录,当然就不需要这个"ignore“的了,也不会遇到上面的错误)。
1 |
git --bare init #to init an empty git repository |
在初始化远程仓库时最好使用 git --bare init 而不要使用:git init
如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上(而且可能会出现上面的错误), 也即在远程仓库的目录下对应的文件还是之前的内容,必须得使用git reset --hard才能看到push后的内容.
默认情况下,git daemon使用的是9418端口,可以用过--port参数来制定使用的端口。
http://www.cnblogs.com/abeen/archive/2010/06/17/1759496.html
http://www.mactech.com/articles/mactech/Vol.24/24.03/SharingwithGIT/index.html
不行阿,一直报错。
服务器端一直拒绝链接,怎么回事阿?
你可以详细说一下你的命令和做的过程。。 “The remote end hung up unexeceptedly.”这个在git clone时就会出现错误吗?是否有可能是server端的防火墙问题,是否允许对9418端口的访问?
The remote end hung up unexeceptedly.
acein@live.cn