Preface
在另一台电脑(服务器)上搭建git仓库,通过SSH上传代码
Server
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
//example:
$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys
$ mkdir /tmp/git
$ cd /tmp/git
$ mkdir project.git
$ cd project.git
$ git init --bare
Initialized empty Git repository in /tmp/git/project.git/
Client
# on John's computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@gitserver:/tmp/git/project.git
$ git push origin master
$ git clone git@gitserver:/tmp/git/project.git
$ cd project
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master
重要
server SSH端口 不是默认的22
1. 显式使用SSH协议
##假设 ip: 1.1.1.1 port: 134
git push ssh://git@1.1.1.1:134/tmp/git/project.git master
- 更改配置文件
~/.ssh/config windows就是C:\Users\*UserName*\.ssh\config
Host 1.1.1.1
port 134