git将本地仓库上传到远程仓库

来源:互联网 发布:编程一小时下载 编辑:程序博客网 时间:2024/06/11 12:54


在已有的Git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中,从而开始一个新的项目

首先,在本地新建文件夹abc,进入到abc里面,然后git init。这样就在本地初始化了一个git项目abc。
然后,登录到远程的git服务器上,到gitrepo目录下面,mkdir abc.git。然后进入abc.git目录。git  --bare init。这样就在服务器端建立了一个空的git项目。
之后,在本地,进入到abc目录里面,增加远程仓库。git remote -v 显示项目目前的远程仓库,因为是新建项目,所以结果为空。git remote add origin git://127.0.0.1/abc.git这样就增加了远程仓库abc。
最后commit提交本地代码,git push origin master这样就把本地的git库上传到了远程git服务器的git库中了

 

也可以不登陆远程直接本地操作

1. git init

2. git add .

3. git commit -am "###"      -------以上3步只是本地提交

4.git remote add origin git@xx.xx.xx.xx:repos/xxx/xxx/xxx.git

5.git push origin 本地分支:远程分支



git clone 

$ git clone <版本库的网址> <本地目录名>
git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子。
$ git clone http[s]://example.com/path/to/repo.git/$ git clone ssh://example.com/path/to/repo.git/$ git clone git://example.com/path/to/repo.git/$ git clone /opt/git/project.git $ git clone file:///opt/git/project.git$ git clone ftp[s]://example.com/path/to/repo.git/$ git clone rsync://example.com/path/to/repo.git/



0 0
原创粉丝点击