1. GitHub 上创建仓库
在 GitHub 页面中 new 一个仓库,仓库名建议和本地文件夹名称保持一致
2. 初始化本地仓库
打开自己的项目文件夹,右键》Git Bash Here,可以快速定位到本地仓库。用命令初始化 Git 仓库
$ git init -b main
-b main 表示同时初始化一个 main 分支
3. add
$ git add .
4. commit
$ git commit -m "First commit"
5. 添加远程仓库的 URL
把远程仓库的 URL 复制下来
$ git remote add origin <REMOTE_URL>
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
6. 推送至远程仓库
推送的时候,可能会让你输入你公钥对应的密码
$ git push origin -u mian
# Pushes the changes in your local repository up to the remote repository you specified as the origin
推送成功之后,回到 GitHub 项目主页,刷新一下,就可以看到我们的代码了