本地代码上传到github仓库

727 阅读1分钟

环境

macOS、VScode

步骤

1:在vscode中打开本地代码文件夹。
2:执行git init。
3:出示化完毕后,文件夹下出现git隐藏文件夹。

image.png

4:将本地仓库remote地址指向github上的空仓库。

git remote add origin https://github.com/uname/storename.git

5:执行

git branch -M main

报错 error: refname refs/heads/master not found

解决办法:先后执行

git add
git commot -m "init"
git branch -M main 

6:执行

git push -u origin main

报错ERROR: Permission to .git denied to user

解决办法:打开 访达->应用程序->实用工具->钥匙串访问

删除相关github.com密钥数据。 删除后,再次执行。

git push -u origin main

报错fatal: unable to access 'https://github.com/uname/storename.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

解决办法:将git的http协议版本默认设置为1.1

git config --global http.version HTTP/1.1

设置后,再次执行

git push -u origin main

上传成功。✌️