在VSCode中配置和使用Github托管代码

1、安装Git

  在Git Bash里输入git --version 如果显示版本号,则说明Git安装成功。

2、在GitHub上新建一个仓库

  例如:myrepo

3、在本地新建一个文件夹,作为VSCode代码的工作文件夹

  例如:mycode

4、mycode既是VSCode的代码工作文件夹又应该是Git的本地仓库

    打开mycode文件夹,右键Git Bash输入git init ,生成一个.git文件夹,就是本地仓库的位置。

5、第一次配置Github的时候需要添加用户名和邮箱

    该用户名和邮箱是注册GitHub时使用的用户名和邮箱,

       git config --global user.name "myname"
       git config --global user.email "myname@mymail.com"

6、生成SSH Key (作用就是从本地仓库向Github远程仓库推送的时候不需要自己再去麻烦的输账号和密码了)

  在终端输入

    ssh-keygen -t rsa -C "myname" (注:myname为你注册Github时的邮箱)  // 实际上这里其实是一个备注功能

  如果执行成功,则返回

    Generating public/private rsa key pair.

    Enter file in which to save the key (c/Users/username/.ssh/id_rsa):      // 这里的username是你电脑上的windows本地账户的用户名

  然后,在这里就是设置存储地址了.我们直接按回车,会出现一下两种情况的一种:

  (1)如果正常运行的话,会出现

        Enter passphrase (empty for no passphrase):

      然后我们直接回车

  (2)有的时候我们可能会出现

        /Users/your username/.ssh/id_rsa already exists.

        Overwrite (y/n)?

    这说明你已经设置了存储地址,我们输入“y”覆盖

        Overwrite (y/n)? y

         回车

    上面的两步的任意一步走完之后,会出现

         Enter same passphrase again: 

    再次回车,这时候你会看见:

         Your identification has been saved in /Users/username/.ssh/id_rsa.
         Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
         The key fingerprint is:
         58:42:8b:58:ad:4b:b5:b9:6d:79:bf:8c:f9:e2:2b:ed username
         The key's randomart image is:
         +--[ RSA 2048]----+
         |    ...          |
         |   o oo.         |
         |  . .ooo.        |
         |    o o+         |
         |   . ..oS.       |
         |    . . + .      |
         |       . o .     |
         |        . o+.    |
         |         +E++.   |
         +-----------------+

  这说明SSH key就已经生成了。保存SSH Key的文件目录就是:/Users/username/.ssh

  我们执行cat命令查看文件的内容:

    cat c/User/username/.ssh/id_rsa.pub

  这时候会看见:

    ssh-rsa AAAAB3NzaC1yc2。。。。。。。。。

  后面的内容我省略了,把显示出来的SSH keys直接添加到github账户设置里边的SSH keys,就添加成功了。


在VSCode中配置和使用Github托管代码