-
首先你电脑上得下载git吧
-
在vscode中设置git
参考
成功后你就会看到
-
下面就是要把本地项目发布到远程仓库上去
(1) 现在gitee上建一个仓库
(2) 以终端操作为例,感觉命令行操作更清晰一点
- git init 初始化仓库
git : 无法将“git”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ git add upload.html
+ ~~~
+ CategoryInfo : ObjectNotFound: (git:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
出先以上错误,那就是你的git没有配全局环境变量
去系统的高级配置中陪一下path=git的bin路径就好了
- 配好后,先提交到本地仓库
PS D:\picJs> git --version
git version 2.37.0.windows.1
PS D:\picJs> git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: getcanvaspixelcolor.js
new file: upload.html
PS D:\picJs> git commit -m "first" upload.html
[master (root-commit) c9a5c16] first
1 file changed, 191 insertions(+)
create mode 100644 upload.html
PS D:\picJs> git commit -m "first" getcanvaspixelcolor.js
[master b5dbdf5] first
1 file changed, 33 insertions(+)
create mode 100644 getcanvaspixelcolor.js
PS D:\picJs> git status
On branch master
nothing to commit, working tree clean
- 看一下远程仓库配置
PS D:\picJs> git remote -v
PS D:\picJs> git remote add for-front https://gitee.com/xxxx/for-front.git
PS D:\picJs> git remote -v
for-front https://gitee.com/xxxx/for-front.git (fetch)
for-front https://gitee.com/xxxx/for-front.git (push)
- 上面远程就配好了,接着就是上传文件
PS D:\picJs> git push for-front master
To https://gitee.com/xxxx/for-front.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/xxxx/for-front.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这里我是第一次上传,出现这样一个错,这是因为我在gitee上仓库的初始化自动生成了readme文件,而本地没有,这就导致两个项目不同
解决方法,就是从仓库上先pull下来,再push
PS D:\picJs> git pull --rebase for-front master
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 1.92 KiB | 393.00 KiB/s, done.
From https://gitee.com/xxxx/for-front
* branch master -> FETCH_HEAD
* [new branch] master -> for-front/master
Successfully rebased and updated refs/heads/master.
PS D:\picJs> git push for-front master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 16 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 3.36 KiB | 3.36 MiB/s, done.
Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.3]
To https://gitee.com/xxxx/for-front.git
9708cf4..7dc6637 master -> master
ok,这就上传成功了。
当然,vscode也内嵌了git常用的命令,无需写命令行