1.创建一个git仓库
- <span style="font-size: 14px;">$ mkdir gittest
- $ cd gittest/
- $ git init
- Initialized empty Git repository in /home/haoqing/workspace/code_celloct/gittest/.git/
- </span>
2.想仓库添加一个文件并提交到本地
- <span style="font-size:14px;">$ echo "first file" >> README
- $ ls
- README
- $ cat README
- first file
- $ git add .
- $ git commit -a -m "add README"
- [master (root-commit) 85b54e5] add README
- 1 file changed, 1 insertion(+)
- create mode 100644 README</span>
2.在本地仓库添加一个远程仓库,并把本地仓库master分支跟踪到远程分支
- $ git remote add origin ssh://haoqing@192.168.1.32/~/workspace/code_celloct/gittest
- $ git push origin master
ssh: connect to host 192.168.1.32 port 22: Connection refused
fatal: The remote end hung up unexpectedly
这是由于openssl服务器没有安装的问题,使用如下命令安装之后就OK了。
- $ sudo apt-get install openssh-server
再次push就OK了:
- $ git push origin master
- The authenticity of host '192.168.1.32 (192.168.1.32)' can't be established.
- ECDSA key fingerprint is df:ed:6e:6f:5e:96:8e:6d:67:9b:c1:d8:a0:9d:f6:81.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added '192.168.1.32' (ECDSA) to the list of known hosts.
- haoqing@192.168.1.32's password:
- Everything up-to-date
命令注释:
第一行:在本地仓库添加一个远程仓库,当然ssh后面的地址是我们本地仓库的地址.
第二行:将本地master分支跟踪到远程分支,在git仓库建立之初就会有一个默认的master分支,当然你如果建立了其他分支,也可以用同样的方法去跟踪.