个人感觉VSCode的git没有IDEA的好用,翻来覆去搞了好多遍才推送上去
1.在gitee上创建一个新的仓库
2.使用VSCode打开项目所在文件夹,如果是拉下来的别人的代码,首先把项目中的.git文件夹删除
3.点击VScode侧边栏的源代码管理,选择初始化仓库
4.点击更改右侧这个+号,这样就能暂存所有更改
5.随便命个名字,就叫初始代码好了,点击提交,代码就上传到本地仓库了
6.之后连接远程仓库,之前看很多教程选择用VSCode的可视化界面来连接,也能链接,但是我在连接好以后在拉取和推送的时候报了很多错误,我也没找到好的解决方法,所以还是选择用命令行连接吧
7.使用这段代码来连接仓库,注意 [ ] 要删除
git remote add origin [url地址]
连接好以后可以再用代码检查一下,有内容显示的话应该没什么问题
git remote -v
8.VSCode之前默认的分支是main,但我们想把它推送到master分支,所以还要把这两者连接一下
git branch --set-upstream-to=origin/远程分支名 本地分支名
运行以后会有报错
PS D:\tools\github\backstage-brain> git branch --set-upstream-to=origin/master main
fatal: the requested upstream branch 'origin/master' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config advice.setUpstreamFailure false"
这个时候就还需要执行一条指令
git config advice.setUpstreamFailure false
重新执行,发现又报错了,fatal: the requested upstream branch 'origin/master' does not exist,哭晕,查了很久资料,原来还得执行一步
git pull origin master --allow-unrelated-histories
这条指令是把仓库里的代码拉下来,空白仓库当然啥也没有,果断选择拉下来,不用担心文件覆盖的问题
再次执行连接的指令,终于连接成功了,之后正常使用就可以了。
总之这比IDEA麻烦太多了,各种小问题层出不穷,而且界面也不是很清晰明了,后面再慢慢摸索吧