为了方便不同空间的人在相同时间协作维护一个工程,觉得有必要搞一个git服务器。
为啥不用svn呢,这个。。。可能是协作开发的更好方式是git吧,现在大多数人都用git的。
=======================================================
最开始参考的这个https://blog.huhamhire.com/viewpost-231.html
yum
install
git
这是用root权限,为系统增加一个账户啊:
root账户新增一个用户git:
[root@CentOS32 ~]# useradd --home /home/git git
[root@CentOS32 ~]# su git[git@CentOS32 root]$ exit
exit
暂时没有设置密码。
这是用root来新增git用户zhangbin吧:
[root@CentOS32 ~]# git config --global user.name "zhangbin"[root@CentOS32 ~]# git config --global user.email "我的邮箱@gmail.com"
这就是新增加的这个系统账户的文件夹:
[root@CentOS32 ~]# ls /home/git[root@CentOS32 ~]# ls -al /home/git
total 32
drwx------. 4 git git 4096 Nov 26 11:33 .
drwxr-xr-x. 6 root root 4096 Nov 26 11:32 ..
-rw-------. 1 git git 5 Nov 26 11:33 .bash_history
-rw-r--r--. 1 git git 18 Jul 18 21:15 .bash_logout
-rw-r--r--. 1 git git 176 Jul 18 21:15 .bash_profile
-rw-r--r--. 1 git git 124 Jul 18 21:15 .bashrc
drwxr-xr-x. 2 git git 4096 Nov 12 2010 .gnome2
drwxr-xr-x. 4 git git 4096 May 2 2013 .mozilla
这个文件是在root的/root下啊。。。。是不是啊。
[root@CentOS32 ~]# mkdir ~/repo[root@CentOS32 ~]# ls /
bin dev home lost+found misc net proc sbin srv tmp var
boot etc lib media mnt opt root selinux sys usr
[root@CentOS32 ~]# rm ~/repo
rm: cannot remove `/root/repo': Is a directory
[root@CentOS32 ~]# rm -rf ~/repo
我还是删掉了。
切换到账户git
[root@CentOS32 ~]# su git
这是说git用户不是root,不能新加一个git 用户zhangbin,是不是啊。
[git@CentOS32 root]$ git config --global user.name "zhangbin"fatal: Cannot change to '/root/..': Permission denied
[git@CentOS32 root]$ ls /root
ls: cannot open directory /root: Permission denied
Password:
[root@CentOS32 ~]# ls /root
anaconda-ks.cfg Documents Music post-install Public Videos
Desktop Downloads Pictures post-install.log Templates
====================================
[root@CentOS32 ~]# su -gitsu: invalid option -- 'g'
Try `su --help' for more information.
必须参考http://blog.chinaunix.net/uid-20940095-id-3447003.html
继续开始搭建git服务器的过程:
[git@CentOS32 root]$ chmod -R 755 /home/git
[git@CentOS32 root]$ ls /home/gti
ls: cannot access /home/gti: No such file or directory
[git@CentOS32 root]$ ls /home/git
[git@CentOS32 root]$ ls -al /home/git
total 32
drwxr-xr-x. 4 git git 4096 Nov 26 14:44 .
drwxr-xr-x. 6 root root 4096 Nov 26 11:32 ..
-rwxr-xr-x. 1 git git 5 Nov 26 11:33 .bash_history
-rwxr-xr-x. 1 git git 18 Jul 18 21:15 .bash_logout
-rwxr-xr-x. 1 git git 176 Jul 18 21:15 .bash_profile
-rwxr-xr-x. 1 git git 124 Jul 18 21:15 .bashrc
drwxr-xr-x. 2 git git 4096 Nov 12 2010 .gnome2
drwxr-xr-x. 4 git git 4096 May 2 2013 .mozilla
==============================
这是git账户创建一个repository啊:
[git@CentOS32 root]$ mkdir /home/git/repo[git@CentOS32 root]$ cd /home/git/repo
[git@CentOS32 repo]$ mkdir test_repo
[git@CentOS32 repo]$ cd test_repo
[git@CentOS32 test_repo]$ git init --bare
Initialized empty Git repository in /home/git/repo/test_repo/
现在还是空的
=======下面是======用zhangbin账户登录,来从git用户负责的repository中clone工程下来======
Password:
[zhangbin@CentOS32 test_repo]$ cd /home/zhangbin
[zhangbin@CentOS32 ~]$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
[zhangbin@CentOS32 ~]$ mkdir testrepos
[zhangbin@CentOS32 ~]$ cd testrepos
[zhangbin@CentOS32 testrepos]$ git clone /home/git/repo/test_repoInitialized empty Git repository in /home/zhangbin/testrepos/test_repo/.git/
warning: You appear to have cloned an empty repository.
test_repo
[zhangbin@CentOS32 testrepos]$ cd test_repo
[zhangbin@CentOS32 test_repo]$ ls
空的。
编辑一个文件,然后上传到git服务器?
[zhangbin@CentOS32 test_repo]$ vim readme.txt[zhangbin@CentOS32 test_repo]$ git add .
[zhangbin@CentOS32 test_repo]$ git commit -a
[master (root-commit) c0955d9] the first git server project for test
Committer: zhangbin <zhangbin@CentOS32.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 3 insertions(+), 0 deletions(-)
create mode 100644 readme.txt
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 352 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To /home/git/repo/test_repo
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to '/home/git/repo/test_repo'
切换到root账户,给refs和objects赋予写权限。
[root@CentOS32 repo]# cd *
[root@CentOS32 test_repo]# ls
branches config description HEAD hooks info objects refs
[root@CentOS32 test_repo]# ls -al
total 40
drwxrwxr-x. 7 git git 4096 Nov 26 14:46 .
drwxrwxr-x. 3 git git 4096 Nov 26 14:46 ..
drwxrwxr-x. 2 git git 4096 Nov 26 14:46 branches
-rw-rw-r--. 1 git git 66 Nov 26 14:46 config
-rw-rw-r--. 1 git git 73 Nov 26 14:46 description
-rw-rw-r--. 1 git git 23 Nov 26 14:46 HEAD
drwxrwxr-x. 2 git git 4096 Nov 26 14:46 hooks
drwxrwxr-x. 2 git git 4096 Nov 26 14:46 info
drwxrwxr-x. 4 git git 4096 Nov 26 14:46 objects
drwxrwxr-x. 4 git git 4096 Nov 26 14:46 refs
[root@CentOS32 test_repo]# chmod 777 -R objects/
[root@CentOS32 test_repo]# chmod 777 -R refs/
[root@CentOS32 test_repo]#
这次push成功了:
[zhangbin@CentOS32 test_repo]$ git push origin masterCounting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 352 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/git/repo/test_repo
* [new branch] master -> master
[zhangbin@CentOS32 test_repo]$