下载和安装软件
1.首先注册一个github账号,https://github.com/
2.安装好Vscode和git,这里用Cmder。

如何在VScode终端使用Cmder,按如下配置(Mac不用配置):
-安装everything,方便搜文件

-在VScode里面用ctrl+shift+P打开设置json

-安装Cmder的Wiki进行设置,下面链接
https://github.com/cmderdev/cmder/wiki/Seamless-VS-Code-Integration#use-cmder-embedded-git-in-vscode
"git.enabled": true,
"git.path": "[cmder_root]\\vendor\\git-for-windows\\cmd\\git.exe",
"terminal.integrated.shell.windows": "[cmder_root]\\vendor\\git-for-windows\\bin\\bash.exe",
复制以上三行命令进行配置,改好Cmder路径

-关闭VScode的所有终端,新建一个终端即可在Vscode里使用Cmder的终端了
建立本地仓库
因为Git就是分布式版本控制系统,分布式的版本控制就是每个人都可以创建一个独立的代码仓库用于管理,各种版本控制的操作都可以在本地完成,所以每台机器都必须自报家门:也就是你的名字和你的Email地址
1.找到程序所在的目录,这个目录就是git的本地仓库,进入目录,先加载6行配置(一定要先加载,否则后面出问题自己解决):
git config --global user.name 你的英文名(name换成你的英文名)
git config --global user.email 你的邮箱(email后面换成你的邮箱)
git config --global push.default simple
git config --global core.quotepath false
git config --global core.editor "code --wait"
git config --global core.autocrlf input

2.初始化本地仓库
输入 git init 初始化本地仓库,文件目录下会创建 .git目录,用来容纳代码变动快照
再在本地仓库下创键一个文件如:index.html

注意:一般情况下.git目录在window系统下是隐藏的,需要手动选择显示,否则有可能找不到.git目录
点击工具→文件夹选项→查看→勾选显示隐藏的文件

3.提交文件到本地仓库
git add index.html
git commit -m “第一次提交”

建立远程仓库
1.github怎么知道是你在操作代码?
用SSH key(Secure Shell Protocol一种安全协议)来验证身份,简单来说,就是github账号里面有一个公钥(解密)和本地仓库的私钥(加密)配对解密,配对成功才能上传本地仓库代码到云端。
2.如何生成SSH key
github上的帮助文档可以参考 https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
-运行 ssh-keygen -t rsa -b 4096 -C 你的邮箱
-回车,在y/n中输入y,出现下列代码说明成功生成ssh key

-输入 cat ~/.ssh/id_rsa.pub 得到一串公钥

-打开github,在页面找到SSH and GPG key输入公钥


-输入 ssh -T git@github.com 检测是否配对成功,如果问yes/no,请回答yes并回车

3.创建远程仓库
-新建github仓库

上传代码到远程仓库
-因为我们前面已经有了本地仓库,只需在Vscode终端运行最后面两行代码,注意一定要使用SSH地址

-运行两行代码如果出现图中错误,是因为远程仓库有改动,这时候只git pull讲远程仓库先更新到本地仓库,然后再git push到远程仓库


-这样index.html就从本地仓库提交到远程仓库了

网友评论