详解Node.js利用node-git-server快速搭建git服务器
本文用到了node-git-server
1、检测本地git版本
该包的使用需要机器上本来就安装git,且git的版本大于等于2.7:
q─root@lt /home/workspace t─# git --version git version 2.7.4
2、利用npm安装包
q─root@lt /home/workspace t─# npm install node-git-server /home/workspace └─┬ [email protected] ├─┬ [email protected] │ ├── [email protected] │ └── [email protected] └── [email protected] npm WARN enoent ENOENT: no such file or directory, open '/home/workspace/package.json' npm WARN workspace No description npm WARN workspace No repository field. npm WARN workspace No README data npm WARN workspace No license field.
有警告可以先忽略~
3、编写example
cd ./node_modules/node-git-server/example/
编辑index.js
const Server = require('node-git-server'); const repos = new Server('/tmp/repos'); const port = process.env.PORT || 80; repos.on('push', (push) => { console.log('push ' + push.repo + '/' + push.commit + ' (' + push.branch + ')' ); push.accept(); }); repos.on('fetch', (fetch) => { console.log('fetch ' + fetch.commit); fetch.accept(); }); repos.listen(port, () => { console.log(`node-git-server running at http://localhost:${port}`) });
4、运行
q─root@lt /home/workspace/node_modules/node-git-server/example t─# node index.js node-git-server running at http://localhost:80
5、测试git服务器
由于我的git服务器是在aliyun上跑的,并且绑定了www.beautifulzzzz.com,所以我先在本地新建一个git仓库,并将其推送同步到云端,然后再clone下来来做测试:
可见将本地git仓库同步到云端和普通的git服务器没有区别,简直太简单方便了!!!
同样git clone也比较简单!
6、云端git仓库的位置
在index.js中我们指定git仓库存放在:const repos = new Server('/tmp/repos');目录下
登录远程服务器可以发现在/tmp/repos/目录下存在我们同步的git仓库:(其中beep.git是之前push的一个)
q─root@lt /tmp/repos t─# ls beautifulzzzz.git beep.git
相关推荐
boneix 2020-10-21
seanzed 2020-10-15
ifconfig 2020-10-14
学留痕 2020-09-20
往后余生 2020-09-17
kka 2020-09-14
redis 2020-09-07
lzccheng 2020-09-06
soyo 2020-08-31
stonerkuang 2020-08-18
LxyPython 2020-08-17
raksmart0 2020-08-17
Lzs 2020-08-14
MrHaoNan 2020-07-31
80530895 2020-07-05
lengyu0 2020-06-28
YarnSup 2020-06-28
huanglianhuabj00 2020-06-27