打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
git 创建远程仓库

使用过Git的都知道,git仓库的任何一个拷贝都可以独立作为一个服务器来使用,那么具体到工作中如何为团队来创建一个git远程仓库呢?下面已一个简单的例子介绍了一些具体步骤。

1.创建一个本地git仓库

[plain] view plain copy
  1. $ mkdir gittest  
  2. $ cd gittest/  
  3. $ git init  
  4. Initialized empty Git repository in /home/xxx/workspace/code_celloct/gittest/.git/  

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

[plain] view plain copy
  1. $ 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  


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

[plain] view plain copy
  1. $ git remote add origin ssh://xxx@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分支,当然你如果建立了其他分支,也可以用同样的方法去跟踪.

经过测试,在另一台机器上已经可以获取到此仓库代码。而且本地有任何更改通过push命令都可以把改动同步提交的远程仓库了。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
02-Git远程仓库Github
笔记《版本控制之道--使用Git》
GIT版本配置管理
Git内部培训课件
Git详解之二 Git基础
推荐!手把手教你使用Git | 互联网的那点事
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服