git 创建远程仓库

  • Post author:
  • Post category:其他


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


1.创建一个本地git仓库

$ mkdir gittest
$ cd gittest/
$ git init
Initialized empty Git repository in /home/xxx/workspace/code_celloct/gittest/.git/


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






$ 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







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









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

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



版权声明:本文为HAOMCU原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。