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

本文详细记录了在CentOS上搭建Git服务器的过程,包括安装配置Git、创建仓库、用户权限设置及首次推送代码等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为了方便不同空间的人在相同时间协作维护一个工程,觉得有必要搞一个git服务器。

为啥不用svn呢,这个。。。可能是协作开发的更好方式是git吧,现在大多数人都用git的。

=======================================================

最开始参考的这个https://blog.huhamhire.com/viewpost-231.html

yuminstallgit



这是用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



[git@CentOS32 root]$ su root
Password: 
[root@CentOS32 ~]# ls /root
anaconda-ks.cfg  Documents  Music     post-install      Public     Videos

Desktop          Downloads  Pictures  post-install.log  Templates


====================================

[root@CentOS32 ~]# su -git
su: 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/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工程下来======


[git@CentOS32 test_repo]$ su zhangbin
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_repo
Initialized empty Git repository in /home/zhangbin/testrepos/test_repo/.git/

warning: You appear to have cloned an empty repository.


[zhangbin@CentOS32 testrepos]$ ls
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





[zhangbin@CentOS32 test_repo]$ git push origin master
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 master
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)
Unpacking objects: 100% (3/3), done.
To /home/git/repo/test_repo
 * [new branch]      master -> master
[zhangbin@CentOS32 test_repo]$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等风来不如迎风去

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值