git hub installation GitHub under the windows, upload process configuration and project details

GitHub under the windows of the installation, configuration and upload process of project details

Overview

This paper describes the installation Github terminal in Win10 system, how to configure the installed terminal and how to use Git Git terminal to upload your project to a remote server

Operation necessary

win10 system computer, a good Internet connection, GitHub account (advance to the official website to register)

GitHub installation

1, the official website to download the installation software GitHub
link is: https: //git-scm.com/download/win
attention to this page after waiting a few seconds will be automatically downloaded, simply double-click to run after the download is complete, follow the instructions to install that is can.
2, the operation after installation required:
2.1 First To Git installation directory is added to the system environment variable:
Right-click the computer - "Properties" - "Advanced System Settings" --- "Environment Variables" - found "Path" under "system variables", click on "New" will just install Git directory can be added to the list:

2.2 enter the command in the local cmd: git --version, if such a situation occurs following the installation was successful!

Initial Configuration of Git

1, open Git terminal
after successful installation in the desktop Start menu will be more than three git XXX (respectively: git bash, git gui, git cmd), click git bash , you can start git terminal.
2, the user name and binding Git mailbox
into the terminal, to enter the following code:

git config --global user.name  (这里是官网注册的用户名)
git config --global user.email (这里是官网注册的邮箱)

As shown below:

3, create a local Git repository with the remote repository
of our own native code or uploaded to the project when we essentially establish a program installed in your local GitHub server "warehouse", and then upload to the Internet connection is located remote server in their own "warehouse" in this specific remote "warehouse" in the code to see whether or not you want to share your own set. Here we describe how to set up two "warehouse."
3.1, create a local Git repository
for example, we want the local disk E disk in whw_demo folder as a local repository:
Method One: Create a file named whw_demo directly to the E drive in the folder, and then you want to upload your own the items are copied to this folder
method 2: git bash terminal to go to the directory E disk, then use the mkdir command to create a new file named whw_demo folder, and then copy the item you want to upload to this folder:

As you can see I created two local warehouses in the E drive.
3.2, create a Git remote repository
Enter the official website, after our own account to log in, click on the "+" sign upper-right corner, then select "New repository":

then we can set the specific properties of this warehouse:

After setting, click Add to generate a remote repository.

Establish a local Git and GitHub remote connections

这一步操作至关重要,只有将Git本地与远程的GitHub建立了连接以后我们本地的项目才能上传至远程服务器
1、Git终端的配置,生成公钥文件,用来连接github
在git终端输入如下命令,然后连续敲3个回车即可
ssh-keygen -t rsa -C (这里是你的邮箱地址)
效果如下:

2、本地的配置
2.1 命令执行成功后,在本地电脑的C:\Users\dell下的名为.ssh的目录下找到名为id_rsa.pub的文件,打开这个文件后将里面的内容先复制下来;
2.2 这里还需要进行的一步操作是:为了防止git连接失败,可在.ssh文件夹下新建一个无后缀的名称为config的文件,在里面加入下面代码:

Host github.com
User git 
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

3、远程的配置
进入到GitHub的官网,点击右上角图标下的settings:

然后,在出现的左边的settings栏目中选择SSH and GPG Keys:

然后在出来的左边的框框中选择 New SSH:

弹出下图:

其中Title可以随意写个名字,Key里面的内容需要将2.1步中复制的id_rsa.pub文件中的内容拷贝进去,注意不是config文件的代码!最后点击Add即可。
4、验证连接是否成功建立
在git终端上输入如下命令:

ssh -T git@github.com

如果出现下图所示的内容说明连接成功

如果出现错误可以尝试通过执行 ssh -T -p 22 [email protected] 命令来解决,其中-p 22表示将服务器端口改为22。

将本地项目上传到GitHub远程服务器

其实,这个过程的实质就是在我们之前创建好的本地仓库与远程仓库之间利用建立好的连接进行项目的上传。
1、包含需要上传项目的本地仓库的配置
1.1 在前面的介绍中,我们已经将自己的项目赋值到了本地仓库——名为whw_demo的文件夹中。现在我们需要在git终端进入这个仓库,然后在里面输入命令:
git init
效果如下(同时会在本地生成一个隐藏的init文件):

1.2 我们上传的项目的名称为WHW_FTP(已将该文件拷贝到whw_demo文件夹下),然后将这个项目提交到仓库中:
git add WHW_FTP
效果如下:

1.3 接着运行下面代码(注意-m后面是注释内容):
git commit -m whw_ftp
效果如下(由于图太长只截取了部分):

这里需要说明的是:
(1)git add . #就可以把所有内容添加到索引库中,注意后面有个点,而且add和点之间有空格
(2)git commit -m “注释内容” #提交索引库中的内容,-m是参数,表示注释内容,主要用来记录此次操作
1.4 然后运行下面代码:
git remote add origin [email protected]:UserName/RepertoryName.git
其中[email protected]:UserName/RepertoryName.git是我们github中仓库的ssh地址,UserName处是用户名,RepertoryName处github远程仓库名(如之前创建的test仓库)。
效果如下:

然后,再输入下面代码:
git push -u origin master
效果如下:

最后,我们在GitHub官网中自己的test远程仓库中可以看到该项目已经上传成功了!

最后需要说明的一点是,如果本地仓库为空是不能提交的,如果运行git push -u origin master出现error错误,一般情况下都是仅进行了init操作,没有进行add与commit操作。

概要

本文主要介绍了在Win10系统中安装Github终端、如何配置安装好的Git终端以及如何利用Git终端将自己的项目上传到远程服务器中

操作必备

win10系统电脑一台、良好的互联网连接、GitHub账户(需要提前到官网进行注册)

GitHub的安装

1、到官网下载GitHub的安装软件
链接为:https://git-scm.com/download/win
注意进入这个网页后等待几秒钟下载会自动进行,下载完毕后直接双击运行,按照说明安装即可。
2、安装完成后需要进行的操作:
2.1 首先要将Git的安装目录加入到系统环境变量中:
右击计算机——“属性”——“高级系统设置”———“环境变量”——找到“系统变量”下的“Path”,点击“新建”,将刚刚安装的Git的目录加进去即可:

2.2 在本地cmd中输入命令:git --version,如果出现下面这样的情况说明安装成功!

Git的初始配置

1、开启Git终端
安装成功后在桌面的开始菜单会多了3个git XXX(分别是:git bash、git gui、git cmd),点击git bash,即可启动git终端。
2、绑定Git的用户名及邮箱
进入终端后,先输入下面的代码:

git config --global user.name  (这里是官网注册的用户名)
git config --global user.email (这里是官网注册的邮箱)

如下图:

3、创建Git的本地仓库与远程仓库
我们将自己本地的代码或者项目上传至GitHub服务器中实质上时我们在自己的本地建立一个装项目的“仓库”,然后通过Internet连接上传到位于远程服务器里自己的“仓库”中,具体这个远程的“仓库”里的代码是否要共享就看自己的设置了。这里我们介绍如何建立这两个“仓库”。
3.1、创建Git的本地仓库
例如,我们想要把本地磁盘E盘里的whw_demo文件夹作为本地仓库:
方法一:直接在E盘里创建名为whw_demo的文件夹即可,然后将自己想要上传的项目复制到这个文件夹里
方法二:在git bash终端中先进入E盘的目录,然后利用mkdir命令新建名为whw_demo的文件夹,然后将自己想要上传的项目复制到这个文件夹里:

大家可以看到我在E盘新建了两个本地仓库。
3.2、创建Git的远程仓库
进入官网,用我们自己的账户登录进去后,点击右上角的“+”号,然后选择“New repository”:

接着我们可以设置这个仓库的具体属性:

设置完毕后点击Add即可生成远程仓库。

本地Git与远程GitHub连接的建立

这一步操作至关重要,只有将Git本地与远程的GitHub建立了连接以后我们本地的项目才能上传至远程服务器
1、Git终端的配置,生成公钥文件,用来连接github
在git终端输入如下命令,然后连续敲3个回车即可
ssh-keygen -t rsa -C (这里是你的邮箱地址)
效果如下:

2、本地的配置
2.1 命令执行成功后,在本地电脑的C:\Users\dell下的名为.ssh的目录下找到名为id_rsa.pub的文件,打开这个文件后将里面的内容先复制下来;
2.2 这里还需要进行的一步操作是:为了防止git连接失败,可在.ssh文件夹下新建一个无后缀的名称为config的文件,在里面加入下面代码:

Host github.com
User git 
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

3、远程的配置
进入到GitHub的官网,点击右上角图标下的settings:

然后,在出现的左边的settings栏目中选择SSH and GPG Keys:

然后在出来的左边的框框中选择 New SSH:

弹出下图:

其中Title可以随意写个名字,Key里面的内容需要将2.1步中复制的id_rsa.pub文件中的内容拷贝进去,注意不是config文件的代码!最后点击Add即可。
4、验证连接是否成功建立
在git终端上输入如下命令:

ssh -T git@github.com

如果出现下图所示的内容说明连接成功

如果出现错误可以尝试通过执行 ssh -T -p 22 [email protected] 命令来解决,其中-p 22表示将服务器端口改为22。

将本地项目上传到GitHub远程服务器

其实,这个过程的实质就是在我们之前创建好的本地仓库与远程仓库之间利用建立好的连接进行项目的上传。
1、包含需要上传项目的本地仓库的配置
1.1 在前面的介绍中,我们已经将自己的项目赋值到了本地仓库——名为whw_demo的文件夹中。现在我们需要在git终端进入这个仓库,然后在里面输入命令:
git init
效果如下(同时会在本地生成一个隐藏的init文件):

1.2 我们上传的项目的名称为WHW_FTP(已将该文件拷贝到whw_demo文件夹下),然后将这个项目提交到仓库中:
git add WHW_FTP
效果如下:

1.3 接着运行下面代码(注意-m后面是注释内容):
git commit -m whw_ftp
效果如下(由于图太长只截取了部分):

这里需要说明的是:
(1)git add . #就可以把所有内容添加到索引库中,注意后面有个点,而且add和点之间有空格
(2)git commit -m “注释内容” #提交索引库中的内容,-m是参数,表示注释内容,主要用来记录此次操作
1.4 然后运行下面代码:
git remote add origin [email protected]:UserName/RepertoryName.git
其中[email protected]:UserName/RepertoryName.git是我们github中仓库的ssh地址,UserName处是用户名,RepertoryName处github远程仓库名(如之前创建的test仓库)。
效果如下:

然后,再输入下面代码:
git push -u origin master
效果如下:

最后,我们在GitHub官网中自己的test远程仓库中可以看到该项目已经上传成功了!

最后需要说明的一点是,如果本地仓库为空是不能提交的,如果运行git push -u origin master出现error错误,一般情况下都是仅进行了init操作,没有进行add与commit操作。

Guess you like

Origin www.cnblogs.com/qj696/p/11204850.html