github的使用简易教程

一、安装git
  https://git-for-windows.github.io/
  git  ->  git bash

二、配置参数
  $ git config --global user.name "Your Name"
  $ git config --global user.email "email@example.com"
eg:注意git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

三、创建版本库
  在目录下执行以下命令
  $ git init
eg:把这个目录变成Git可以管理的仓库

  编辑 .txt文件
eg:记得把Notepad++的默认编码设置为UTF-8 without BOM

四、添加版本库
  $ git add readme.txt
   提交版本库
   $ git commit -m "write a readme file"
eg:  " " 中纯属解释说明
 
五、版本库操作
    1、git status
    2、git diff  readme.txt   查看修改的内容
    3、git log
    4、git reset --hard HEAD^
    5、git reset --hard HEAD^^
    6、git reset --hard HEAD~100
    7、git reset --hard 3628164   3628164为commit id
    8、git reflog   记录每一次命令
    9、git checkout -- readme.txt   把readme.txt文件在工作区的修改全部撤销
eg:一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。
    10、git rm test.txt  删除文件
    11、git rm -rf dir   删除文件夹
    
    
六、创建远程仓库
    1、创建SSH Key
      $ ssh-keygen -t rsa -C "youremail@example.com"
eg:如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人
    2、登陆GitHub,打开“Account settings”,“SSH Keys”页面:
    3、add SSH Key 粘贴id_rsa.pub文件的内容
    
七、添加远程库
    1、github上 Create a new repository ——>  Demo
    2、本地仓库  $ git remote add origin git@github.com:NewbieAce/Demo.git
              或 $ git remote add origin  https://github.com/NewbieAce/Demo.git
  eg:origin:远程仓库
    3、把本地内容推送到远程
        $ git push -u origin master
        
八、从远程库克隆
    1、在github上创建库时勾选Initialize this repository with a README,这样GitHub会自动为我们创建一个README.md文件
    2、$ git clone git@github.com:NewbieAce/Demo.git
    
    

ps:详细教程见

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

原文地址:https://www.cnblogs.com/theWayToAce/p/5553159.html