1、安装git
sudo apt-get install git
2、创建账户git
创建Linux账户git,用来运行git服务
sudo adduser git
3、创建证书登录
收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入/home/git/.ssh/authorized_keys文件里,一行一个。
如果没有该文件创建它:
cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
这里的路径中的git是账户名的名称,/home/账户名/.ssh/authorized_keys,必须要所属账户下。
4、初始化git仓库
首先我们选定一个目录作为Git仓库,假定/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:
cd /home
mkdir gitrepo
chown git:git gitrepo/
cd gitrepo
git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/
以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:
chown -R git:git runoob.git
5、克隆仓库
git clone git@192.168.1.107:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
至此,我们的git仓库就搭建完毕了!!!
第一次添加tmpfs.c文件到git仓库出错处理:
root@ubuntu:/home/imhqq/share/runoob# git push origin master
git@192.168.1.107's password:
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 987 bytes | 987.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
error: remote unpack failed: unable to create temporary object directory
To 192.168.1.107:/home/gitrepo/runoob.git
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git@192.168.1.107:/home/gitrepo/runoob.git'
解决办法:
chmod 777 -Rf /home/gitrepo/
root@ubuntu:/home/imhqq/share/runoob# git push origin master
git@192.168.1.107's password:
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 987 bytes | 329.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.1.107:/home/gitrepo/runoob.git
* [new branch] master -> master
root@ubuntu:/home/imhqq/share/runoob#
root@ubuntu:/home/imhqq/share/runoob# git status
On branch master
Your branch is up to date with 'origin/master'.
网友评论