您的位置:首页 > 运维架构 > Linux

基于centos6.3第一次搭建一个git 服务器

2013-11-26 15:41 459 查看
为了方便不同空间的人在相同时间协作维护一个工程,觉得有必要搞一个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]$ exitexit暂时没有设置密码。这是用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/gittotal 32drwx------. 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 .bashrcdrwxr-xr-x. 2 git git 4096 Nov 12 2010 .gnome2drwxr-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 varboot etc lib media mnt opt root selinux sys usr[root@CentOS32 ~]# rm ~/reporm: 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 /rootls: cannot open directory /root: Permission denied[git@CentOS32 root]$ su rootPassword: [root@CentOS32 ~]# ls /rootanaconda-ks.cfg Documents Music post-install Public VideosDesktop 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服务器的过程:[root@CentOS32 ~]# su git[git@CentOS32 root]$ chmod -R 755 /home/git[git@CentOS32 root]$ ls /home/gtils: cannot access /home/gti: No such file or directory[git@CentOS32 root]$ ls /home/git[git@CentOS32 root]$ ls -al /home/gittotal 32drwxr-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 .bashrcdrwxr-xr-x. 2 git git 4096 Nov 12 2010 .gnome2drwxr-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 --bareInitialized empty Git repository in /home/git/repo/test_repo/现在还是空的=======下面是======用zhangbin账户登录,来从git用户负责的repository中clone工程下来======[git@CentOS32 test_repo]$ su zhangbinPassword: [zhangbin@CentOS32 test_repo]$ cd /home/zhangbin[zhangbin@CentOS32 ~]$ lsDesktop 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.[zhangbin@CentOS32 testrepos]$ lstest_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 basedon 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.comIf 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[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)error: insufficient permission for adding an object to repository database ./objectsfatal: failed to write objecterror: unpack failed: unpack-objects abnormal exitTo /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]# lsbranches config description HEAD hooks info objects refs[root@CentOS32 test_repo]# ls -altotal 40drwxrwxr-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 HEADdrwxrwxr-x. 2 git git 4096 Nov 26 14:46 hooksdrwxrwxr-x. 2 git git 4096 Nov 26 14:46 infodrwxrwxr-x. 4 git git 4096 Nov 26 14:46 objectsdrwxrwxr-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]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: