My learn of git

这篇文章记录我从零开始学习git的过程.

我的git最开始是在廖雪峰git教程学习的。

安装git

我的git是在github 下载的mysysgit 然后打开安装包,一路点下去就好了。

然后就可以在右键菜单里面发现git bash的选项了。

git-bash-示例

学习基本的git命令

我第一个学会的命令是 git init

git-init-命令示例

然后是 git config 命令

1
2
git config --global user.name "sparkrat"
git config --global user.email "sparkrat@163.com"

这个设置很重要哦@O_O@/

git-config-命令示例

然后可以在这个文件夹里面做一些事情,例如写一些代码什么的。。

接下来的命令就是 git addgit commit
我一般直接用

1
2
git add --all
git commit -m "a hint message"

菜鸟无需知道太多技巧,用多了以后慢慢就知道了。。

一些必须掌握的命令

然后我现在还掌握的命令有

1
2
3
4
5
6
7
8
9
10
11
12
13
git status
git rm < a file >
git checkout -- < a file >
git clone remoteReponame
git remote add remoteReponame remoteRepoAddress
# remoteRepoAddress 可以有多种协议,最常用的有两种:
# 使用https协议: https://github.com/username/reposityName.git
# 使用ssh协议: git@github.com:username/reposityName.git
git push remoteReponame brachName
git remote remove remoteReponame
git reset --hard HEAD(^(^(^)))
git log (--pretty=oneline)
git reflog (--pretty=oneline)

使用sshkey让push更方便

还有,不得不说的一件事就是,一开始我一直用的https协议进行push的,但是这样麻烦死人。因为每次都需要输github账号密码。后来我发现,用shh协议可以想push就push。。炒鸡方便嗄。

首先,用 ssh-keygen -t rsa -C "youremail@example.com" 生成一个rsa文件,在用户文件夹的.ssh文件夹(好像是隐藏文件夹)里面。
生成的时候所有的选择都选择默认,看到下面的内容的时候说明生成成功了。

ssh-keygen-命令示例

用记事本打开id_rsa.pub(公钥),把文件内容复制到github的-用户设置-SSHkeys-addkey里面。

添加rsa公钥到github示例

这样之后在往github上push你的repo就不需要再输入账号密码。

用git pages搭建博客

学会用git和github的remoteRpo之后,用它来干点什么呢?

当然是弄个pages博客啦啦啦。

  1. 首先去找一个模板吧,去github的搜索框里面搜jekyll关键字!!
    嘎嘎嘎一堆模板出来了。
  2. 然后clone到你的电脑吧。
  3. 再然后新建一个名字叫做yourusername.github.io的repo吧。
  4. 然后把你在第二步里面clone下来的repo名字改成yourusername.github.io吧
  5. 把修改好的repo push到你的github里面吧!!
  6. 然后在浏览器地址栏里面输入yourusername.github.io看看效果吧。
  7. 给你的博客修改样式,添加文章吧。

我的git学习之路大致就是这样的了。 还有就是,如果想用github的pages搭建博客,markdown不能不学啊。

当然,知道一些基础的语法就可以了,不需要学的很深入。markdown的学习可以穿插在写博客文章的中间,慢慢学。

程序猿,你要学的东西还很多,慢慢学吧。


update 2015-06-03

the new command I learned

1
2
3
4
5
6
git checkout -b newbranch      //create a new branch and switch to it
//it also equal to the next two command
git branch newBranchName //create a new branch
git chekcout branchName //switch to a brach
git remote show remotereponame //see the details of remote repo
git merge branchName //merge a branch to current brach