vscode上传代码到github
·
一、新建仓库




到了这个页面停住,因为红框里面的代码是有用的,也可以从这里复制:
echo "# HarmonyOS-Health-app" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/lion-kng/HarmonyOS-Health-app.git
git push -u origin main
以下是对代码的解释
echo "# HarmonyOS-Health-app" >> README.md
git init //初始化
git add README.md
git commit -m "first commit"
git branch -M main //确定为main分支
git remote add origin https://github.com/lion-kng/HarmonyOS-Health-app.git //关联github与本地代码,这一步最重要!!!
git push -u origin main //上传代码
git remote add origin https://github.com/lion-kng/HarmonyOS-Health-app.git
是这样构成的 git remote add origin 项目链接
链接从这里获得

二、在文件夹中配置git
打开项目所在的文件夹,右键打开git bash


把前面那个代码全部一起复制过去就可以,它自己会一条一条执行。复制用右键
三、vscode上传本地代码

在vscode中已经可以看到仓库的信息了

分支也是前面选好的main分支

点提交。以后的上传也直接点提交就可以,不用和git bash交互了

之后他让你提交信息,这个信息就是简述一下这次提交代码有什么改动,可以随便写

之后点同步更改

在github上刷新一下,可以看到项目被上传上去了
四、额外提示
分支可能默认是master而不是main,但是现在一般都是用main,所以想改为main的话,用这个代码:
git config --global init.defaultBranch main
随便打开一个git bash把这个代码复制进去就可以,因为它改的是全局的跟你在哪里打开没关系。
这样以后默认的都是main了
也可以把前面的git init换为
git init -b main
-b main表示在初始化时直接创建名为main的默认分支。
这个只对本项目有效
有的时候在上传或者同步代码的时候可能会报Couldn‘t connect to server
看了这篇博客
解决访问Github出现的Couldn‘t connect to server错误_github couldn't connect to server-CSDN博客

就在要上传项目的终端输入这两行代码
git config --global --unset http.proxy
git config --global --unset https.proxy
但是不一定有效。
之前的经验发现用手机热点上传成功率会高一点
更多推荐
所有评论(0)