Github入门教程

0.安装

mac和Linux默认预装git
windows:https://git-for-windows.github.io/
安装过程中仔细阅读安装流程,普通用户选择默认选项即可。

1.初始设置

输入命令:

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

字符串根据自己的姓名和邮箱地址填写

$ git config --global color.ui auto

使命令的输出有更高的可读性

2.创建账户&设置SSH KEY

创建账户不赘述
SSH KEY作用:
http://www.cnblogs.com/ayseeing/p/3572582.html
https 和 SSH 的区别:
1、前者可以随意克隆github上的项目,而不管是谁的;而后者则是你必须是你要克隆的项目的拥有者或管理员,且需要先添加 SSH key ,否则无法克隆。

2、https url 在push的时候是需要验证用户名和密码的;而 SSH 在push的时候,是不需要输入用户名的,如果配置SSH key的时候设置了密码,则需要输入密码的,否则直接是不需要输入密码的。

生成SSH KEY:

$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Baoxue1008/.ssh/id_rsa):
Created directory '/c/Users/Baoxue1008/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Baoxue1008/.ssh/id_rsa.
Your public key has been saved in /c/Users/Baoxue1008/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:BmdMG+QehYZz445xebzzXTS6qV5G27WAkRGYQ/FagkA [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    .E o=+=o.    |
|      ++*B. o    |
|      .*B=.=     |
|      .=+.* o  ..|
|       =So o o..o|
略

中途会让你设置密码

添加公开密钥:
在Github主页右上角选择Your profile,在右侧选择SSH and GPG keys。添加KEY时Title自己设置,Key输入刚生成的公钥。
使用该命令查看:

$ cat ~/.ssh/id_rsa.pub

复制时要包括头和尾的全部信息。

使用私钥和Github通信:

$ SSH -T git@github.com

在主页创建一个新repository,供下节内容使用。

3.上传/下载代码:

下载:

在要下载的repository主页,点击拷贝该项目的http url,并在你想下载代码的路径下使用:

git clone yoururl

上传:
在本地项目文件夹添加/修改文件后,执行:

git status

会显示所有被修改过的文件。

对新文件执行:

git add newfile

完成向暂存区添加文件。

再执行:

git commit -m "本次提交文字注释"

完成提交

最后执行:

git push

上传。这里会需要你输入用户名和密码

你可能感兴趣的:(github,git)