操作环境
Windows7(32bit)
前提条件
1、完成msysgit工具安装。下载路径:官网或百度网盘路径Git-2.15.0-32-bit.exe。安装方法为默认选项执行。
2、已注册github账户。假设注册用户名为lion123,注册邮箱为[email protected]
3、本地已创建项目,路径:E:\SHELL。就是一个文件夹包含需要上传的文件。
操作步骤
1、选择"开始" -> "所有程序" -> Git -> Git Bash,进入命令行界面。
2、执行命令 ssh-keygen -t rsa -C "[email protected]" 生成SSH key,全部默认,直接回车。
[email protected]2052250 MINGW32 ~ $ ssh-keygen -t rsa -C "[email protected]" 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 [email protected]163.com The key‘s randomart image is: +---[RSA 2048]----+ | o+=B#B| | .o++X.+| | o=.O | | . .+ *o=| | S E*.o+| | . o . .+..o | | o . . o= .| | ...o | | .. | +----[SHA256]-----+ [email protected]-2052250 MINGW32 ~
查看./.ssh目录下的文件
[email protected]2052250 MINGW32 ~ $ cd .ssh [email protected]-2052250 MINGW32 ~/.ssh $ ls -al total 25 drwxr-xr-x 1 Administrator 197121 0 十一 11 07:36 ./ drwxr-xr-x 1 Administrator 197121 0 十一 11 07:35 ../ -rw-r--r-- 1 Administrator 197121 1675 十一 11 07:36 id_rsa -rw-r--r-- 1 Administrator 197121 405 十一 11 07:36 id_rsa.pub [email protected]-2052250 MINGW32 ~/.ssh $ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfC4E/GnLVKYKGq1Qp4Apz6n+Smpo9dE1ah50JPIT3C2YDXqOK+MI56kJbmBNyOb7+NTqZzpbvqlkEkKtvohIdN1XgB1u+qsVMtdYlQjTObi4ccHOig+omMgojDAUkoZ5nJz7Ervo0NABiw77AFXmny7UprFIPLZDmFdDeUgF5Vje0zlf9CjzWDk+oHhwuFCkG69gD17o0HgWLbV+EMx2sbHJNYD36cxSb [email protected]163.com [email protected]-2052250 MINGW32 ~/.ssh
3、登录github账户,打开账户下的setting设置,将id_rsa.pub内容复制。
4、校验本地与GitHub间SSH信任关系
$ ssh -T [email protected] 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上创建方法如下
创建完成后可以通过如下方法获取SSH地址,下面需要用到。
6、在msysgit里进入本地项目的路径E:\shell并执行如下相关命令
[email protected]2052250 MINGW32 ~/.ssh $ cd e: [email protected]-2052250 MINGW32 /e $ cd shell [email protected]-2052250 MINGW32 /e/shell $ git init Initialized empty Git repository in E:/SHELL/.git/ [email protected]-2052250 MINGW32 /e/shell (master) $ git add . [email protected]-2052250 MINGW32 /e/shell (master) $ git config --global user.email "[email protected]" [email protected]-2052250 MINGW32 /e/shell (master) $ git remote add orgin "[email protected]:lion123/Shell.git" [email protected]-2052250 MINGW32 /e/shell (master) $ git push -u orgin master Counting objects: 3, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 2.52 KiB | 859.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To github.com:linyongfeng5555/Shell.git * [new branch] master -> master Branch ‘master‘ set up to track remote branch ‘master‘ from ‘orgin‘. [email protected]-2052250 MINGW32 /e/shell (master) $
7、查看github上shell项目是否有本地项目上传的文件。
8、查看到相关文件,操作完成。
时间: 2024-10-28 20:58:44