windows下Git详细安装教程&&环境配置教程&&配置公私钥上传码云和github

1、下载git

进入git官网选择对应版本

2、 详细安装过程

step1:

Please read the following important information before continuing(继续之前,请阅读以下重要信息)

Step 2

Select Destination Location(选择安装位置)

Step 3

Select Components(选择组件)

Additional icons(附加图标)

        On the Desktop (在桌面上)

Windows Explorer integration Windows(资源管理器集成鼠标右键菜单)

        Git Bash Here

​        Git GUI Here

Git LFS (Large File Support)(大文件支持)

Associate .git* configuration files with the default text editor(将 .git 配置文件与默认文本编辑器相关联)

Associate .sh files to be run with Bash(将.sh文件关联到Bash运行)

Use a TrueType font in all console windows(在所有控制台窗口中使用TrueType字体)

Check daily for Git for Windows updates(每天检查Git是否有Windows更新)

Step 4

Select Strat Menu Folder(创建开始菜单目录)

Step 5

 Choosing the default editor used by Git(选择Git使用的默认编辑器)

Use the Nano editor by default(默认使用 Nano 编辑器)

Use Vim (The ubiquitous text editor) as Git's default editor(使用 Vim 作为 Git 的默认编辑器)

Use Notepad++ as Git's default editor(使用 Notepad++ 作为 Git 的默认编辑器)

Use Visual Studio Code as Git's default editor(使用 Visual Studio Code 作为 Git 的默认编辑器)

Step 6

Adjusting your PATH environment

配置PATH环境

Use Git from Git Bash only

        This is the safest choice as your PATH will not be modified at all.You will only be able to use the Git command line tools              form Git Bash.

        这是最安全的选择,因为您的PATH根本不会被修改。您只能使用 Git Bash 的 Git 命令行工具。

Use Git from the Windows Command Prompt

       This option is considered safe as it only adds some minimal Git wrappers to your PATH to avoid cluttering your                             environment with optional Unix tools . You will be able to use Git from both Git Bash and the Windows Command Prompt.

         这个选项被认为是安全的,因为它只向PATH添加一些最小的 Git包,以避免使用可选的Unix工具混淆环境。 您将能够从               Git Bash 和 Windows 命令提示符中使用 Git。

Use Git and optional Unix tools from the Windows Command Prompt(从Windows命令提示符使用Git和可选的Unix工具

           Both Git and the optional Unix tools will be added to you PATH

          Git和可选的Unix工具都将添加到您计算机的 PATH 中

          Warning:This will override Windows tools like "find and sort".Only use this option if you understand the implications.

          警告:这将覆盖Windows工具,如 “ find 和 sort ”。只有在了解其含义后才使用此选项。

Step 7

Choosing HTTPS transport backend(选择HTTPS传输后端

Use the OpenSSL library(使用 OpenSSL 库

      Server certificates will be validated using the ca-bundle.crt file.

       服务器证书将使用ca-bundle.crt文件进行验证。

Use the native Windows Secure Channel library(使用本地 Windows 安全通道库

       Server certificates will be validated using Windows Certificate Stores.This option also allows you to use your company's             internal Root CA certificates distributed e.g. via Active Directory Domain Services.

        服务器证书将使用Windows证书存储验证。此选项还允许您使用公司的内部根CA证书,例如, 通过Active Directory                    Domain Services 。

Step 8

Configuring the line ending conversions(配置行结束转换)

Checkout Windows-style,commit Unix-style line endings

Git will convert LF to CRLF when checking out text files.When committing text files,CRLF will be converted to LF .For cross-pltform projects,this is the recommended setting on Windows ("core.autocrlf" is set to "true")

在检出文本文件时,Git会将LF转换为CRLF。当提交文本文件时,CRLF将转换为LF。 对于跨平台项目,这是Windows上推荐的设置(“core.autocrlf”设置为“true”)

Checkout as-is , commit Unix-style line endings

Git will not perform any conversion when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects,this is the recommended setting on Unix ("core.autocrlf" is set to "input")

在检出文本文件时,Git不会执行任何转换。 提交文本文件时,CRLF将转换为LF。 对于跨平台项目,这是Unix上的推荐设置 (“core.autocrlf”设置为“input”)

Checkout as-is,commit as-is

Git will not perform any conversions when checking out or committing text files.Choosing this option is not recommended for cross-platform projects ("core.autocrlf"is set to "false")

在检出或提交文本文件时,Git不会执行任何转换。对于跨平台项目,不推荐使用此选项(“core.autocrlf”设置为“false”)

Step 9

Configuring the terminal emulator to use with Git Bash(配置终端模拟器以与 Git Bash 一起使用)

Use MinTTY (the default terminal of MSYS2)

Git Bash will use MinTTY as terminal emulator,which sports a resizable window,non-rectangular selections and a Unicode font. Windows console programs (such as interactive Python) must be launched via 'winpty' to work in MinTTY.

Git Bash将使用MinTTY作为终端模拟器,该模拟器具有可调整大小的窗口,非矩形选区和Unicode字体。 Windows控制台程序(如交互式Python)必须通过'winpty'启动才能在MinTTY中运行。

Use Windows' default console window

Git will use the default console window of Windows ("cmd.exe"),which works well with Win32 console programs such as interactive Python or node.js , but has a very limited default scroll-back,needs to be configured to use aUnicode font in order to display non-ASCII characters correctly,and prior to Windows 10 its windows was not freely resizable and it only allowed rectangular text selections.

Git将使用Windows的默认控制台窗口(“cmd.exe”),该窗口可以与Win32控制台程序(如交互式Python或node.js)一起使用,但默认的回滚非常有限,需要配置为使用unicode 字体以正确显示非ASCII字符,并且在Windows 10之前,其窗口不能自由调整大小,并且只允许矩形文本选择。

Step 10

Configuring extra options(配置额外的选项)

Enable file system caching(启用文件系统缓存)

File system data will be read in bulk and cached in memory for certain operations ("core.fscache" is set to "true"). This provides a significant performance boost.

文件系统数据将被批量读取并缓存在内存中用于某些操作(“core.fscache”设置为“true”)。 这提供了显着的性能提升。

Enable Git Credential Manager(启用Git凭证管理器)

The Git Credential Manager for Windows provides secure Git credential storage for Windows,most notably multi-factor authentication support for Visual Studio Team Services and GitHub. (requires .NET framework v4.5.1 or or later).

Windows的Git凭证管理器为Windows提供安全的Git凭证存储,最显着的是对Visual Studio Team Services和GitHub的多因素身份验证支持。 (需要.NET Framework v4.5.1或更高版本)。

Enable symbolic links(启用符号链接)

Enable symbolic links (requires the SeCreateSymbolicLink permission).Please note that existing repositories are unaffected by this setting.

启用符号链接(需要SeCreateSymbolicLink权限)。请注意,现有存储库不受此设置的影响。

Step 11

Installing

Step 12

Completing the Git Setup Wizard

三、配置Git环境

1.、点击 "Git Bash" 打开 Git 命令控制台

2、生成秘钥文件来连接 GitHub,在控制台输入如下指令并连续敲 3 次回车即可

    $ ssh-keygen -t rsa -C "[email protected]"

    备注:"[email protected]" 是你的邮箱地址,需要注意的是 "ssh-keygen" 之间是没有空格的,其他的之间是有空格的。

 3、秘钥生成后可以在 "C:\Users\Administrator\.ssh" 文件夹下找到秘钥文件 "id_rsa.pub"。linux系统在/root/.ssh下

四、通过码云来管理代码

1、到码云后台

2、将刚才生成的id_rsa.pub拷贝过去

3、新建项目projectShangCheng

4、 配置全局的用户名和邮箱

5、按照下面提示依次执行即可

执行git add . 提交全部

假如本地仓库已经存在了代码而远程仓库里有更新,需要将更改的内容合并到本地的代码中

    $ git fetch origin    

    备注:获取远程更新。

    $ git merge origin/master 

    备注:将更新的内容合并到本地分支。

    $ git push -u origin master

五、通过GitHub来管理代码

1、 注册并登录 GitHub 账号

2、上传公钥至github环境

点击用户头像指示的三角图标选择 "Settings"

然后选择 "SSH and GPG keys"

点击右侧 "SSH keys" 栏中的 "New SSH key" 按钮进行配置(其中 Title 可以自己随意起一个名字,而 Key 的内容就是将 "id_rsa.pub" 文件中的内容全部复制过来即可)

点击 "Add SSH key" 按钮完成操作,此时在你填写的邮箱中会收到一封确认的邮件可以不用管它。

3、 验证 Git 环境是否配置成功

$ ssh -T [email protected]

备注:

(1) 当提示输入(yes/no)? 时,在后面输入 yes 回车即可,如果看到欢迎语 "Hi xxx! You've successfully authenticated, but GitHub does not provide shell access" 则表示配置成功。

(2) 如果提示类似 "ssh: Could not resolve hostname \342\200\223t: Name or service not known" 的错误,解决办法是执行命令:ssh -t -p 22 [email protected](其中 -p 表示修改服务器端口为22)。

GIt 环境配置成功

4、 配置全局的用户名和邮箱

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

    $ git config --global user.email "[email protected]"

    备注:"userName" 和 "[email protected]" 分别是你自己的用户名和邮箱。

5、 创建存储仓库上传本地代码

新建存储仓库

    点击右上角加号箭头,在弹出的菜单中选择 "New repository" 选项进行仓库配置。

    (1)> Repository name:存储库名称

    (3)> Description:对此仓库的描述

    (3)> 自由选择:Public(公共)或Private(私人)仓库

    (4)> 自由选择:是否勾选 "Initialize this repository with a README"

         备注:1. 如果是新创建的仓库可以选择勾选

                    2. 如果要导入现有存储库可以选择不勾选

    点击 "Create repository" 按钮进行仓库创建。

配置存储仓库

 若选择了 "README" 选项,那么在创建仓库成功后可以点击 "README.md" 文件来修改并编译此文件。

根据提示,在本地项目目录打开Git命令窗口,上传代码即可,注意使用git add .能将所有代码上传

操作界面如下 

上传完毕刷新页面 就可以看到提交的代码。

上传项目说明

(1)如果在 GitHub 上创建仓库的时候将 "README" 选项选择了则就已经算是一次提交了,若需要在本地同步远程仓库的内容则使用如下命令即可

 $ git pull [email protected]:userName/hello-word.git 

或者 

$ git pull origin master

执行如上命令成功后在将会在本地仓库的根目录下生成从远程仓库同步下来的 "README.md" 文件。

(2)添加当前更改或新增文件到本地 Git 仓库中

    1> 添加指定文件

    $ git add hello-word.txt

    备注:添加当前目录中的 "hello-word.txt" 文件到本地 Git 仓库中。

    1> 添加全部文件

    git add .

    备注:"add" 后面加点意思就是将本仓库中的所有内容添加到本地仓库中。

(3)提交当前工作空间的修改内容

    $ git commit -m "XXX"

    备注:"XXX" 是提示信息,此提示信息是一定要写的,不仅是规则同时也方便我们记录此次操作的是什么内容。

(4)推送本地仓库内容到远程仓库

    $git push [email protected]:userName/projectName.git

    或者 

    $ git push -u origin master

    备注:"userName" 是我们 GitHub 账号的用户名,"projectName.git" 是我们为这个项目建立的仓库名。

(5)如果出现 "non-fast-forward" 错误,主要是因为 GitHub 仓库中已经存在有一部分内容了,所以它不允许你直接把你的内容覆盖上去,比如有的人在新建仓库配置信息时将 "README" 文件选项打钩了可能就会出现这种情况,此时可以使用如下方法解决

    $ git push --all -f

    备注:强推即利用覆盖方式将你本地的代码替代 GitHub 仓库内的内容

(6) 至此上传文件就结束了,你可以到你的 GitHub 项目主页(https://github.com/userName/projectName.git) 看到从本地仓库上传到 GitHub 远程仓库的文件了。

六、GIt常见功能管理

1. 增加、修改或删除了新文件

    $ git add .

    $ git commit -m "XXX"

    $ git push origin master

    或者

    $ git push -u origin master

2. 从远程仓库克隆内容至本地仓库

    $ git clone [email protected]:userName/hello-word.git

    备注:"userName" 是我们 GitHub 账号的用户名,"hello-word.git" 是我们为这个项目建立的仓库名。

3. 假如本地仓库已经存在了代码而远程仓库里有更新,需要将更改的内容合并到本地的代码中

    $ git fetch origin    

    备注:获取远程更新。

    $ git merge origin/master 

    备注:将更新的内容合并到本地分支。

发布了139 篇原创文章 · 获赞 146 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/TCF_JingFeng/article/details/89476423