首页 > 其他 > 详细

实例:git创建远程仓库

时间:2017-02-17 00:52:17      阅读:218      评论:0      收藏:0      [点我收藏+]

思路:


一.远程仓库所需要的命令

二.通过https://github.com网站注册并建立一个远程仓库

三.实例操作如何把文档放到远程仓库上





一.远程仓库相关命令


检出仓库:$ git clone git://github.com/jquery/jquery.git

查看远程仓库:$ git remote -v

添加远程仓库:$ git remote add [name] [url]

删除远程仓库:$ git remote rm [name]

修改远程仓库:$ git remote set-url --push [name] [newUrl]

拉取远程仓库:$ git pull [remoteName] [localBranchName]

推送远程仓库:$ git push [remoteName] [localBranchName]

 

*如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下:

$git push origin test:master         // 提交本地test分支作为远程的master分支

$git push origin test:test              // 提交本地test分支作为远程的test分支





二.登录https://github.com建立一个新账号


1.先注册一个账号,https://github.com,创建自己的git,点repositiories,在点new


2.名称自定义(testgit),然后选public ,点create repository


3.添加key:右上角点自己的头像,选择settings,左侧选SSH and GPG keys


技术分享技术分享


4.左侧点New SSH key,把linux机器上的~/.ssh/id_rsa.pub内容粘贴到这里 


技术分享 技术分享


技术分享技术分享

技术分享

注:本地端的操作


key在服务器上生成秘钥


ssh-keygen


远程仓库放入生成的秘钥,添加完后自动收到一份邮件


技术分享


5.把本地仓库推送到远程仓库


本机进入home的目录下


本地创建testgit仓库,并进入仓库目录


技术分享

技术分享

初始化仓库


git init


技术分享技术分享

                                                           

6.git remote add origin git@github.com:lizheng103/testgit.git (lizheng103为计算机名,testgit为仓库名)

远程创建的仓库testgit,名字尽量要和本地一致


技术分享技术分享




三.实例创建一个文档推送到远程仓库上


1.创建一个文件


vi test.txt


技术分享

技术分享技术分享


2.git push-u origin master //把本地的testgit仓库推送到远程的testgit下


技术分享


查看远程仓库新建的内容

技术分享

技术分享


3.修改文档后再查看仓库里的内容


vi test.txt 修改内容


git add test.txt


git commit -m "change test.txt"


技术分享技术分享


修改完成后把本机的文件推送到远程仓库


git push


修改后的仓库内容


技术分享技术分享


8.以后每次再推送,就可以直接git push


实例:git创建远程仓库

原文:http://11937277.blog.51cto.com/11927277/1898464

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!