这里介绍一下如何通过本地命令行远程控制 Github 仓库的创建、更新与删除。
准备工作
我们先需要去主页>Settings>Developer Settings>Personal access tokens>Tokens (classic) 创建一个 token,并且需要为该token设置以下权限:
- repo
- repo:status
- repo_deployment
- public_repo
- repo:invite
- security_events
- delete_repo
创建仓库
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/user/repos \
-d '{"name":"Hello-World","description":"This is your first repo!","private":false}'
参考资料:GitHub docs: Create a repository for the authenticated user
更新仓库
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO \
-d '{"name":"a new repo name","description":"a new description","private":false}'
删除仓库
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO