Create a Github repository from command line

前端 未结 4 1252
死守一世寂寞
死守一世寂寞 2020-12-01 16:30

I have been trying to push my local repo changes to github from command line. I have been away from git for a while now so I don\'t remember a few things. For the past hour

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 17:09

    The answer by mickiewicz using the REST API via curl has numerous deficiencies which are addressed in this answer. Notably, this answer:

    1. authorizes against GitHub using the necessary token authorization, not the obsolete password authentication
    2. makes curl exit with a nonzero code in case of an error (via -f)
    3. parameterizes the repo name
    4. makes a private repo (default is public)

    First, obtain a token with access to the repo scope.

    REPO_NAME=foo1
    GITHUB_TOKEN=0000000000000000000000000000000000000000  # Enter your own.
    
    curl -f -X POST \
      -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/user/repos -d "{\"name\": \"${REPO_NAME}\", \"private\": true}"
    

    This answer is relevant only for creating a repository under a user. The request for creating a repository under an organization is slightly different.

    If you don't mind installing the GitHub CLI, refer to the answer by VonC instead.

提交回复
热议问题