你可能不需要安装Git Server也可以实现项目同步

2019-12-10  本文已影响0人  懂事的观众

​ 如果你只是单纯的想跟朋友同步一下代码,那么在服务器上装一个Gitlab实在是不划算。我们直接用简单粗暴的方法实现需求。

​ 假设你有一台服务器(例如我的Ubuntu),一个客户端(Windows),实现方案如下。

安装git

配置客户端登录服务器

# 生成RSA密钥
ssh-keygen -t rsa

# 将客户端公钥上传到服务器的认证公钥文件authorized_keys
cat ~/.ssh/id_rsa.pub | ssh user@remote-server "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

​ 现在客户端已经可以通过密钥直接登录到服务器。

服务器端创建项目

# 路径配置
jay@ubuntu:~$ pwd
/home/jay

# 创建项目文件夹
jay@ubuntu:~$ mkdir Project.git
jay@ubuntu:~$ cd Project.git/
# 创建一个空的git 库
jay@ubuntu:~/Project.git$ git init --bare
Initialized empty Git repository in /home/jay/Project.git/

客户端同步项目

$ git clone ssh://user@remote-server/home/jay/Project.git
Cloning into 'Project'...
warning: You appear to have cloned an empty repository.
# 添加远程仓库
git remote add origin ssh://user@remote-server/path-on-server.git

# 如果本地已经有个commit,就可以提交到远程服务器上。
git push origin master
上一篇 下一篇

猜你喜欢

热点阅读