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

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

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

安装git

  • 在服务端:sudo apt-get install git-core
  • 在客户端:去git官网下载安装即可。

配置客户端登录服务器

  • 打开Windows上的Git Bash。
# 生成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 Bash里面操作。
$ 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

你可能感兴趣的:(你可能不需要安装Git Server也可以实现项目同步)