1. sudo apt-get install git-core gitosis git-daemon-run
[安装必要的组件]
2. create the git user and disable the password.
# sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
[此操作的作用是:添加一个没有密码的系统级用户,其用户名:git,其home目录是/home/git,使用/bin/sh作为其shell] After this operation, the git user has been successfully created.
3. Initiate the gitosis repositories.
sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub (the id_rsa.pub is the administrator of this respositories, 如果没有生成此key,运行ssh-keygen命令)
If successfully, you will see
==> Initialized empty Git repository in /home/git/repositories/gitosis-admin.git
==> Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git
4. If you want other's can access the /home/git/repositories, you need to
# sudo chmod 777 -R /home/git/repositories
5. Administory the gitosis and add project in gitosis.conf file
# git clone git@<ip-addr>:gitosis-admin.git
# cd gitosis-admin
# vim gitosis.conf
Add the following lines
==> [group test]
==> writable = test
==>members = <name> (<name> can be found list in gitosis-admin/keydir, without .pub)
然后,再把更改进行提交,push到server上面。
6. Create the test project
# mkdir test
# cd test
# git init
# touch test.txt
# git add .
# git commit -am "test file for test project"
# git remote add origin git@<ip_addr>:test
# git push origin master:refs/heads/master
7. Clone the test project on other place
# git clone git@<ip-addr>:test.git
If all the steps are work well, the git server has been succussfully set up.
If you want to browser the repositories through brower, it needs the gitweb's help
8. Set up gitweb
# sudo apt-get install gitweb
The gitweb need the apache to support it
# sudo apt-get install apache2
# sudo vim /etc/gitweb.conf [更改里面的路径,指向现在repositories的路径]
After this, we can open browser to browse the repositories
http://<ip-addr>/cgi-bin/gitweb.cgi
But it is a little hard to view. It can be solved as following
# cd /var/www
# sudo ln -s /user/share/gitweb/* .
Then re-browse the repositories, it display well.
9. we need to go to git repositories and make the project visual in gitweb
# chmod 777 * -R
-----------------------------------在使用中遇到的问题---------------------------------------------------------
1. git在push的时候出现insufficient permission for adding an object错误
解决:
在git库目录下:
$ chown -vR git *