git 创建远程仓库

23 篇文章 0 订阅
21 篇文章 0 订阅

1.创建一个git仓库

[plain]  view plain copy
  1. <span style="font-size: 14px;">$ mkdir gittest  
  2. $ cd gittest/  
  3. $ git init  
  4. Initialized empty Git repository in /home/haoqing/workspace/code_celloct/gittest/.git/  
  5. </span>  

2.想仓库添加一个文件并提交到本地

[plain]  view plain copy
  1. <span style="font-size:14px;">$ echo "first file" >> README  
  2. $ ls  
  3. README  
  4. $ cat README   
  5. first file  
  6. $ git add .  
  7. $ git commit -a -m "add README"  
  8. [master (root-commit) 85b54e5] add README  
  9.  1 file changed, 1 insertion(+)  
  10.  create mode 100644 README</span>  

2.在本地仓库添加一个远程仓库,并把本地仓库master分支跟踪到远程分支

[plain]  view plain copy
  1. $ git remote add origin ssh://haoqing@192.168.1.32/~/workspace/code_celloct/gittest  
  2. $ 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了。

[plain]  view plain copy
  1. $ sudo apt-get install openssh-server  

再次push就OK了:

[plain]  view plain copy
  1. $ git push origin master   
  2. The authenticity of host '192.168.1.32 (192.168.1.32)' can't be established.  
  3. ECDSA key fingerprint is df:ed:6e:6f:5e:96:8e:6d:67:9b:c1:d8:a0:9d:f6:81.  
  4. Are you sure you want to continue connecting (yes/no)? yes  
  5. Warning: Permanently added '192.168.1.32' (ECDSA) to the list of known hosts.  
  6. haoqing@192.168.1.32's password:   
  7. Everything up-to-date  

命令注释:

第一行:在本地仓库添加一个远程仓库,当然ssh后面的地址是我们本地仓库的地址.
第二行:将本地master分支跟踪到远程分支,在git仓库建立之初就会有一个默认的master分支,当然你如果建立了其他分支,也可以用同样的方法去跟踪.

经过测试,在另一台机器上已经可以获取到此仓库代码。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值