建立一个自己的git仓库服务器
转载自:https://bbs.ecoo.top/forum.php?mod=viewthread&tid=25&highlight=git
在机顶盒的NAS里,可以建立一个属于自己的私人git服务器,
并且可以做到拉取github上的仓库转为自己的私有仓库,
还能做到自行更新github上的大神的仓库到本地。
建立服务器仓库
apt install git gitweb nginx spawn-fcgi fcgiwrap
## 添加一个新的nginx的网页block
# /etc/nginx/sites-available/git
server {
listen 8011;
listen [::]:8011;
#replace "example.com" below with your domain (or subdomain)
#server_name ;
#ssl_certificate /etc/nginx/cert/xxx.crt;
#ssl_certificate_key /etc/nginx/cert/xxx.key;
location /index.cgi {
root /usr/share/gitweb/;
include fastcgi_params;
gzip off;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location / {
root /usr/share/gitweb/;
index index.cgi;
}
location ~ /clone(/.*) {
client_max_body_size 0;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_PROJECT_ROOT /var/lib/git;
fastcgi_param PATH_INFO $1;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
#fastcgi_param GIT_HTTP_EXPORT_ALL "";
}
}
激活这个nginx 如果想获得ssl证书443访问,请自行添加ssl
sudo ln -sf /etc/nginx/sites-{available,enabled}/git
sudo systemctl restart nginx
允许任何人使用 git clone https://git.example.com/clone/NAME 对 gitweb 中显示的仓库进行 clone,为此使用 git-http-backend。在/etc/nginx/sites-available/git 的 server 块中加入
location ~ /clone(/.*) {
client_max_body_size 0;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_PROJECT_ROOT /var/lib/git;
fastcgi_param PATH_INFO $1;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
git-http-backend 会检查 bare repo 中是否有 git-daemon-export-ok 这个文件,如果没有则不允许 clone,这正好是 gitweb 配置中表示「公有仓库」使用的文件。如果想对所有的仓库都允许 clone,则可以添加一个 fastcgi param:
fastcgi_param GIT_HTTP_EXPORT_ALL "";
这个 HTTP clone 只是一个只读的 clone,如果想要 push 还需使用 SSH。
创建一个测试仓库并标记为公开,再添加一个说明
cd
git init --bare test.git
touch test.git/git-daemon-export-ok
echo 'Test repo' > test.git/description
通过 gitweb.conf 配置了仓库的路径,现在就可以往里面加东西了。注意,你只应该往里面加祼仓库,而不应带上工作目录.
可以直接 clone 一个:
root@ubuntu:~# cd /var/lib/git
root@ubuntu:/var/lib/git# ls
root@ubuntu:/var/lib/git# git clone --bare https://github.com/movsb/taoblog.git
Cloning into bare repository 'taoblog.git'...
remote: Counting objects: 1969, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 1969 (delta 5), reused 0 (delta 0), pack-reused 1950
Receiving objects: 100% (1969/1969), 475.01 KiB | 167.00 KiB/s, done.
Resolving deltas: 100% (1370/1370), done.
Checking connectivity... done.
还可以直接软连接过来:
root@ubuntu:/var/lib/git# ln -s ~/taoexec/.git taoexec.git
root@ubuntu:/var/lib/git# ls
taoblog.git taoexec.git
root@ubuntu:/var/lib/git# ll
total 12
drwxr-xr-x 3 root root 4096 Jun 15 23:53 ./
drwxr-xr-x 37 root root 4096 Dec 19 03:57 ../
drwxr-xr-x 7 root root 4096 Jun 15 23:50 taoblog.git/
lrwxrwxrwx 1 root root 18 Jun 15 23:53 taoexec.git -> /root/taoexec/.git/
上面的文档位置都是参考,待编辑。请自行修改。等有时间再做一个详细的小白版。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。