下午研究了一下如何在vscode上利用git上传代码到github,这样可以方便在不同的地方都能看到自已的代码。

主要工作

1.安装vscode

2.安装git並连接github

1.安装vscode

安装vscode,网址:https://code.visualstudio.com/download

一直按确定就可以了

2.安装git并连接github

然后是下载git,网址:https://git-scm.com/download

也是一直按确定

这里选择以vscode作为预设的editor,在终端输入git init

git init

再输入git config --globaluser.name“yourname”

​git config --globaluser.name“yourname”

其中“yourname”填的是你github的名字

再来输入git config --globaluser.email“email@email.com

git config --globaluser.email“email@email.com“

之后你可以输入git config --global --list

​git config --global --list

检查自已有没有输错

再来要生成一个ssh key放到github中

继续在终端输入ssh-keygen -t rsa -C“email@email.com

ssh-keygen -t rsa -C“email@email.com“

同理,“email@email.com“输入的是你github绑定的邮箱

一路回车,在出现选择时输入Y,再一路回车直到生成密钥。会在/Users/***/路径下生成一个.ssh文件夹,密钥就存储在其中。

可以在提示的那个/Users/xx/路径中用记事本打开id_rsa.pub

并把那段内容复制到github的setting的SSH and GPG keys,选择add keys

把那段文字复制并保存

之后可以在vscode的终端输入ssh -Tgit@github.com

ssh -Tgit@github.com

之后会有个提示你输入yes,就可以连接成功了

然后再去github建一个仓库,

建完后会看到有个ssh的地址

然后在vscode的终端输入git remote add origin git@github.com:xxx.git

git remote add origin git@github.com:xxx.git

git@github.com:xxx.git输入的是你的地址

在vscode上开一个文件随便打一段代码,可以看到有个叉的那个选项多了个下标

然后可以按try.cpp那一栏的那个+号

按上面那个勾,然后在那个栏输入master

之后按push,就可以把代码上传到github了!

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐