Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Create_Repo.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Create Repo

Give Feedback | Bug report

Tags: #github #productivity #code #operations #snippet

Last update: 2023-04-12 (Created: 2023-02-28)

Description: This notebook provides instructions on how to create a repository on GitHub.

Input

Importing library

import requests import json

Variable

# Enter your username here user_name = "*********" # Enter Your github token github_token = "*************" # Enter your repo name that you want to create repo_name = "*************" # Enter Your repo description repo_description = "This is another repo"

Model

payload = {"name": repo_name, "description": repo_description, "auto_init": "true"} repo_request = requests.post( "https://api.github.com/" + "user/repos", auth=(user_name, github_token), data=json.dumps(payload), )

Output

if repo_request.status_code == 422: print("Github repo already exists try wih other name.") elif repo_request.status_code == 201: print("Github repo has created successfully.") elif repo_request.status_code == 401: print("You are unauthorized user for this action.")