每个人。 我想通过 CLI 使用访问令牌创建 Github 存储库 我想使用具有以下功能的命令提示符。
1:从 github 克隆存储库 2:在我的github帐户上创建存储库 3:将该存储库添加到我的 Github
所有工作必须通过 CLI 完成 有谁知道如何做到这一点吗?
我尝试过 CLI,但效果不佳。
做起来非常简单:
#!/bin/bash
# Your GitHub token
# Generate the token under your github account
GITHUB_TOKEN="ghp_xxxxx"
# The GitHub API URL for creating a new repository
API_URL_CREATE="https://api.github.com/user/repos"
###
### Create the repository
###
# The JSON data to send in the POST request
DATA="{\"name\":\"$REPO_NAME\"}"
# Use curl to send a POST request to the GitHub API to create a new repository
curl -H "Authorization: token $TOKEN" -d "$DATA" $API_URL_CREATE
###
### Verify that the repository exists
###
USER_NAME=xxxxx
# The API for getting the repository information
API_URL_GET="https://api.github.com/repos"
# Send a GET request to the GitHub API to "get" the repository details
RESPONSE=$(curl -s -H "Authorization: token $TOKEN" $API_URL_GET/$USER_NAME/$REPO_NAME)
# Check if the repository exists
if [[ $RESPONSE == *"Not Found"* ]]; then
echo "Repository does not exist"
else
echo "Repository exists"
fi