Windows上传代码到github操作指导

时间:2022-04-17 18:15:34

操作环境

Windows7(32bit)

前提条件

1、完成msysgit工具安装。下载路径:官网或百度网盘路径Git-2.15.0-32-bit.exe。安装方法为一路Next按照默认选项执行就可以。

2、已注册github账户。假设注册用户名为lion123,注册邮箱为lion123@163.com

3、本地已创建项目,路径:E:\SHELL。就是一个文件夹包含需要上传的文件。

操作步骤

1、选择"开始" -> "所有程序" -> Git -> Git Bash,进入命令行界面。

2、执行命令 ssh-keygen -t rsa -C "lion123@163.com" 生成SSH key,全部默认,直接回车。

Administrator@YLMF123- MINGW32 ~
$ ssh-keygen -t rsa -C "lion123@163.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:
SHA256:rNxdaz+MMY2R0zbwd8BwRzjRTj47BHhFbhTWBZGYWO4 lion123@.com
The key's randomart image is:
+---[RSA ]----+
| o+=B#B|
| .o++X.+|
| o=.O |
| . .+ *o=|
| S E*.o+|
| . o . .+..o |
| o . . o= .|
| ...o |
| .. |
+----[SHA256]-----+ Administrator@YLMF123- MINGW32 ~

进入./.ssh目录,查看id_rsa.pub文件

Administrator@YLMF123- MINGW32 ~
$ cd .ssh Administrator@YLMF123- MINGW32 ~/.ssh
$ ls -al
total
drwxr-xr-x Administrator 十一 : ./
drwxr-xr-x Administrator 十一 : ../
-rw-r--r-- Administrator 十一 : id_rsa
-rw-r--r-- Administrator 十一 : id_rsa.pub Administrator@YLMF123- MINGW32 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfC4E/GnLVKYKGq1Qp4Apz6n+Smpo9dE1ah50JPIT3C2YDXqOK+MI56kJbmBNyOb7+NTqZzpbvqlkEkKtvohIdN1XgB1u+qsVMtdYlQjTObi4ccHOig+omMgojDAUkoZ5nJz7Ervo0NABiw77AFXmny7UprFIPLZDmFdDeUgF5Vje0zlf9CjzWDk+oHhwuFCkG69gD17o0HgWLbV+EMx2sbHJNYD36cxSb lion123@
.com

Administrator@YLMF123- MINGW32 ~/.ssh

3、登录github账户,打开账户下的setting设置,将id_rsa.pub内容复制。

Windows上传代码到github操作指导

4、校验本地与GitHub间SSH信任关系

$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi lion123! You've successfully authenticated, but GitHub does not provide shell access.

5、在Github里新建项目,项目名称与本地项目文件夹名称相同(E:\shell),名字为shell。github上创建方法如下

Windows上传代码到github操作指导

创建完成后可以通过如下方法获取SSH地址,后续操作需要用到。

Windows上传代码到github操作指导

6、在msysgit里进入本地项目的路径E:\shell并执行如下相关命令

Administrator@YLMF123- MINGW32 ~/.ssh
$ cd e:

Administrator@YLMF123- MINGW32 /e
$ cd shell Administrator@YLMF123- MINGW32 /e/shell
$ git init
Initialized empty Git repository in E:/SHELL/.git/ Administrator@YLMF123- MINGW32 /e/shell (master)
$ git add . Administrator@YLMF123- MINGW32 /e/shell (master)
$ git config --global user.email "lion123@163.com" Administrator@YLMF123- MINGW32 /e/shell (master)
$ git remote add orgin "git@github.com:lion123/Shell.git" Administrator@YLMF123- MINGW32 /e/shell (master)
$ git push -u orgin master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), 2.52 KiB | 859.00 KiB/s, done.
Total (delta ), reused (delta )
To github.com:linyongfeng5555/Shell.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'orgin'. Administrator@YLMF123- MINGW32 /e/shell (master)
$

7、查看github上shell项目是否有本地项目上传的文件。

Windows上传代码到github操作指导

8、查看到相关文件,操作完成。