创建github账号,新建仓库
创建token
设置过期时间,勾选权限范围,点击底部的【Generate Token】按钮,创建完成
命令行初始化git仓库,提交源码到本地仓库
echo "# GithubTest" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/xxx/GithubTest.git
命令行push到github
git push -u origin main
按提示输入github账号,密码输入之前创建好的token,显示如下内容说明已经上传成功
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 236 bytes | 236.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/qdcosin/GithubTest.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
Xcode中push到github
提交修改本地仓库
勾选push可将修改同步推送到github
同样会提示输入账号和token
注意
push命令时,提示输入github账号密码的地方,原本是可以使用密码来验证,但是August 13, 2021起验证方式改变了,如果仍然输入密码,会得到如下提示,请按之前步骤创建token,token可以设置过期时间及权限范围,相较以前直接使用账号、密码登录,提高了安全性和可控性
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for '<https://github.com/qdcosin/MacOS-SwiftUI-StatusBar.git/>'