Use Github/Gogs Api To Create Repo

Table of Contents

Gogs implemented Github api. The only different is the URL.


No matter you are using Gogs or Github, you have to login your account and generate a token.


Go into Settings -> Applications, then click Generate New Token.


Go into Settings -> Developer settings -> Personal access tokens, then click Generate new token.

In both cases, copy&paste the token into a file right away. We will need it in our script/function below.

zsh function



  TOK="Your token here"

  # Gogs url
  #URL="https://<your gogs domain>/api/v1"

  # Github url


  curl \
  -H "Content-Type: application/json" \
  -H "Authorization: token ${TOK}" \
  -d "${REQ}" \

The only difference between gogs and github is the URL. Gogs need /api/v1 in its url, while github uses api sub-domain. Uncomment the one you want to use.

Add function in .zshrc and use as follow:

create_new_repo <repo_name>
John Siu
Minimize the Effort, Maximize the Effect!
comments powered by Disqus