git及github的使用

来源:互联网 发布:淘宝卖家设置发货地址 编辑:程序博客网 时间:2024/04/25 09:36

       因公司要求需要接触版本控制,现在版本控制大家很熟悉的就是分布式的GIT版本控制和SVN集中式版本控制。有接触过CSDN创建项目的同学也知道这里也是用的GIT版本控制。

其实在网上找找都能找到相关教程,但我在这里还是给大家推荐以下两个网站。一来是自己用的时候可以直接这里打开链接方便查询,二来是也方便大家。

       一、文档。这份文档是廖雪峰老师写的,写的很不错。简单易懂易学,能把大家带进门,后面还是要大家多用。其实有linux的基础就是最后不过了,里面的shell命令都是想通的。

      网址:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

     二、视频。这是CSDN做的视频,我实在是听不下那老师讲话的声音,也就没看,直接看的是廖老师的文档,文档有点长,不喜欢看文档的同学视频是个不错的选择。

      网址:http://edu.csdn.net/course/detail/1223/19443?auto_start=1

    下面就只是简单的记录一下自己学的东西,忘了之后自己可以到这里来查查。

     可以到这个网站https://git-for-windows.github.io/上下载git,然后就是简单的安装。本来想写来着,但我发现有一个中文版的命令,大家直接看中文版的就OK。

     网站:https://github.com/flyhigher139/Git-Cheat-Sheet/blob/master/Git%20Cheat%20Sheet-Zh.md?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io


     向github上传自己的代码,现在github上创建一个代码库,再将这个代码库克隆到本地磁盘

       git clone git@github.com : bibiyaya/android_kernel_samsung.git   

    git clone https://github.com:/bibiyaya/s3c6410.git

此时用ls查看本地文件,发现会多了一个s3c6410/,就是说明你把代码库克隆下来了。接下来就是上传你自己的代码,还是那几步:

         1)、git add startup.s

         2)、git commit -m "first_commit"
                         [master c296167] first_commit
                        1 file changed, 557 insertions(+)
                         create mode 100644 startup.s

        3)、git remote add origin https://github.com/bibiyaya/s3c6410.git
                          fatal: remote origin already exists.

到第三步时出现了错误,显示origin名字已经存在,因为之前我上传过一次文件。这里就把origin删除,

         git remote rm origin(所以还是要对基本的shell命令有一定的了解)之后再执行,

          git remote add origin https://github.com/bibiyaya/s3c6410.git

之后就可以把代码push上次,执行:git push  origin master 。 WHAT???又有错误error :failed to push som refs to ......我们应该先把远程服务器的上面的github上面的文件先拉下来,执行: git pull  origin master

最后执行: git push  origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 3.35 KiB | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bibiyaya/s3c6410.git
    0062fc2..c296167  master -> master

好了,这下传完了,你可以登录你的github可以看到你的文件上传成功。


小结命令:

 mkdir test  cd test  git init  touch README  git add README  git commit -m 'first commit'  git remote add origin git@<span style="background-color: rgb(255, 255, 102);">github</span>.com:bibiyaya/test.git 
<span style="white-space:pre"></span>(git remote rm origin)  git push -u origin master

         

0 0
原创粉丝点击