2015年12月01日 GitHub入门学习(二)手把手教你Git安装

时间:2022-03-13 12:03:31

序:Mac与Linux中,Mac都预装了Git,各版本的Linux也都提供了Git的软件包。下面手把手教你Windows下的安装。

一、Git Windows GUI 下载地址

msysgit

https://git-for-windows.github.io/

由于我的网络不能FQ,因此我找到了一个国内下载站,地址:http://www.xiazaiba.com/html/29352.html

二、安装one by one

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

选择需要的组件,直接下一步。

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

设置环境变量,利用msysGit的Git Bash命令提示符,所以选择Use Git from Git Bash only.

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

GitHub中公开的代码大部分都是以Mac或Linux中的LF(Line Feed)换行。然而,由于Windows中是以CRLF(Carriage Return + Line Feed)换行的,所以在非对应的编辑器中将不能正常显示。

换行符在签出时会自动转换为CRLF,在提交时则会自动转换为LF。

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

GIT需要修改注册表,360等杀毒软件可能会提醒,选择允许就可以。

2015年12月01日 GitHub入门学习(二)手把手教你Git安装

三、初始设置

打开程序中的git bash命令提示符窗口,git bash会默认定位到系统盘administrator目录。

  • 设置姓名和邮箱

    设置使用Git时的用户名和邮箱地址,设置的姓名和邮箱地址会用在Git的提交日志中。由于在Github上公开仓库时,这里的姓名和邮箱地址也会随着提交日志一同被公开,所以请不要使用不便公开的隐私信息。而且尽量用英文。

      $ git config --global user.name "name"

      $ git config --global user.email "example@mail.com"

    执行后,会在~/.gitconfig文件中输出如下内容:

      [user]
      name = name
      email = example@mail.com

    

  • 提高命令输出的可读性

    将color.ui设置为auto可以让命令的输出拥有更高的可读性

      $ git config --global color.ui auto

    执行后,会在~/.gitconfig文件中输出如下内容:

      [user]
      name = name
      email = example@mail.com
      [color]
      ui = auto

    

四、创建公开密钥认证所需的SSH Key

运行下面命令创建SSH Key,,Github上连接已有仓库时的认证,是通过使用了SSH的公开密钥认证方式进行的

$ ssh-keygen -t rsa -C "example@mail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):按回车键
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):输入密码
Enter same passphrase again:再次输入密码

输入密码后:

Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
fingerprint值 example@mail.com
The key's randomart image is:
+--[ RSA 2048]----+
| .+o. .E.. |
| . .o..o oo . |

注意会在目录下生产.ssh目录,目录下有两个文件id_rsa文件是私有密钥,id_rsa.pub是公开密钥。