git,github使用

上个周末 学习 了git和github的使用,而本周主要学习了Linux 上电启动过程和Grub的相关内容,github,git这块就暂时放下了。这两天我装个3个Liunx系统,还有熟悉我新买的kindle fire HD,没写一篇git和github的文章,昨天我又复习了下,今天就写篇文章。

     git是啥我就不说了,我觉这是Linus这个大神对世界的另一个巨大贡献,github是个很好的创意,它可以让你的项目托管其上, 自己辛苦积累的代码,如果不托管在github,一旦硬盘坏了,或者重装系统容易丢失自己重要的代码

    我就把我的第一个github的项目建立的方法写一遍。可能方式不太正规,请路过的高手指正。

    第一步安装git
 
  1. sudo apt-get install git-core
    第二步 设置自己的名字和Email,这是你提交commit时候的签名。

  1. root@manu:~# git config --global user.name "manuscola"
  2. root@manu:~# git config --global user.email "manuscola@163.com"
   这时候,会在你的home目录创建一个隐藏文件.gitconfig:
  1. root@manu:~# cat ~/.gitconfig 
  2. [user]
  3.     name = manuscola
  4.     email = manuscola@163.com
  5. root@manu:~#
   第三步 生成SSH key

  1. root@manu:~# mkdir .ssh
  2. root@manu:~# ssh-keygen -"manuscola@163.com" -t rsa 
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/root/.ssh/id_rsa): /home/manu/.ssh/id_rsa
  5. Enter passphrase (empty for no passphrase): 
  6. Enter same passphrase again: 
  7. Your identification has been saved in /home/manu/.ssh/id_rsa.
  8. Your public key has been saved in /home/manu/.ssh/id_rsa.pub.
  9. 。。。。。。。
   你会在自己输入的路径下看到两个文件:

  1. root@manu:~# cd .ssh/
  2. root@manu:~/.ssh# ll
  3. 总用量 16
  4. drwxr-xr-x 2 root root 4096 11月 10 23:11 ./
  5. drwxr-xr-x 34 manu manu 4096 11月 10 23:06 ../
  6. -rw------- 1 root root 1766 11月 10 23:11 id_rsa
  7. -rw-r--r-- 1 root root 399 11月 10 23:11 id_rsa.pub
    第四步注册一个github号,这个就不多说了。和普通的注册一样。

    第五步设置github的SSH key。

   
   点击中间那个图表,设计帐号信息。选择SSH keys,然后选择Add SSH key.

   给ssh key起个名字,然后将生成的id_rsa.pub的内容拷贝进key输入框
中。

--------------------------------------------------------------------------------------------
    至此,git 和github之间配置部分就结束了,剩下的就是如何建一个工程,如何在本地修改后提交上github。

    第一步:
    github上创建一个空工程。
    比如我创建一个buddy的工程,点击上面图表第一个图标就行。

    第二步
   把 github上的空工程拉下来:

   
  1. root@manu:~/code/c# git clone https://github.com/manuscola/buddy.git
  2. Cloning into 'buddy'...
  3. warning: You appear to have cloned an empty repository.
  4. root@manu:~/code/c# ll
  5. 总用量 12
  6. drwxr-xr-x 3 root root 4096 11月 10 23:16 ./
  7. drwxr-xr-x 4 root root 4096 11月 10 20:40 ../
  8. drwxr-xr-x 3 root root 4096 11月 10 23:19 buddy/
  9. root@manu:~/code/c# cd buddy/
  10. root@manu:~/code/c/buddy# ll
  11. 总用量 12
  12. drwxr-xr-x 3 root root 4096 11月 10 23:19 ./
  13. drwxr-xr-x 3 root root 4096 11月 10 23:16 ../
  14. drwxr-xr-x 7 root root 4096 11月 10 23:19 .git/
     第三步:为工程添加或者修改你的代码

  1. root@manu:~/code/c/buddy# ll
  2. 总用量 28
  3. drwxr-xr-x 3 root root 4096 11月 10 23:30 ./
  4. drwxr-xr-x 3 root root 4096 11月 10 23:16 ../
  5. -rw-r--r-- 1 root root 5698 11月 10 23:30 buddy.c
  6. -rw-r--r-- 1 root root 522 11月 10 23:27 buddy.h
  7. -rw-r--r-- 1 root root 938 11月 10 23:30 buddy_test.c
  8. drwxr-xr-x 7 root root 4096 11月 10 23:19 .git/
     第四步:把更新的内容添加到索引中
   
  1. root@manu:~/code/c/buddy# git add .
  2. root@manu:~/code/c/buddy#
     现在就为commit 做好的准备,你可以使用git diff 再加上--cached参数,可以看那些改动将被提交:

  1. root@manu:~/code/c/buddy# git diff --cached 
  2. diff --git a/buddy.c b/buddy.c
  3. new file mode 100644
  4. index 0000000..189cc62
  5. --- /dev/null
  6. +++ b/buddy.c
  7. @@ -0,+1,209 @@
  8. +#include"buddy.h"
  9. +#include<stdio.h>
  10. +#include<assert.h>
  11. +#define _XOPEN_SOURCE 600
  12. +#define _GNU_SOURCE
  13. +#include<stdlib.h>
  14. +#define IS_POWER_OF_2(x) (!((x)&((x)-1)))
  15. 。。。。。。。
    第五步:git commit

  1. git commit -"most code implementation"
    这时候,github的buddy工程中还没有没有我们的改动:

    第六步:推送提交到github


  1. root@manu:~/code/c/buddy# git push -u origin master
  2. Username for 'https://github.com': manuscola
  3. Password for 'https://manuscola@github.com': 
  4. To https://github.com/manuscola/buddy.git
  5.  * [new branch] master -> master
  6. Branch master set up to track remote branch master from origin.
    这个步骤完成后,我们可以看到,我们新增的3个文件,在github上可以看到了。
    我们可以看下git 的log :

 
  1. root@manu:~/code/c/buddy# git log
  2. commit e16877291c4f650f894922647872000be9353105
  3. Author: manuscola <manuscola@163.com>
  4. Date: Sat Nov 10 23:42:26 2012 +0800

  5.     most code implementation


备注:github我用的也不熟,在高手眼里,可能不太正规,git命令理解的也还不深入,还是记录下来整个流程,欢迎大牛前来指导。本来这周应该学习git的使用的,但是必须要先把工作中遇到的问题解决好,所以花了很多的时间学习init 启动过程和grub的内容。等有时间间,我希望能学习整理出一份grub的学习心得出来。

参考文献:
1  Git Community Book 中文版
2  github help
 :Create A Repo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值