Last active
December 25, 2017 19:16
-
-
Save py-ranoid/bf11e12ed7795ed69bb01fc899f4682a to your computer and use it in GitHub Desktop.
Create git repository with remote to github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,requests,sys | |
# import argparse | |
# parser = argparse.ArgumentParser(description='repo name') | |
# parser.add_argument("-n", "--name", help="Name",default='Meh') | |
# args = parser.parse_args() | |
# value = args.name | |
value = sys.argv[1] | |
os.system('git init '+value) | |
os.chdir(value) | |
data = { | |
"name": value, | |
"description": value, | |
"private": True, | |
"has_issues": True, | |
"license_template":'mit', | |
"has_projects": True, | |
"has_wiki": True | |
} | |
# Get your key here : https://github.com/settings/tokens | |
header = {'Authorization':'token xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'} | |
url = 'https://api.github.com/user/repos' | |
x = requests.post(url,json=data,headers=header) | |
ret = x.json() | |
if 'errors' in x: | |
print x['errors'] | |
elif x.status_code == 201: | |
sshurl = x.json()['ssh_url'] | |
os.system('git remote add origin '+ sshurl) | |
os.system('git pull origin master') | |
""" | |
To create a bash alias : | |
Add this line to ~/.bashrc | |
alias gitnew='python ~/path-to-script/githubinit.py' | |
>> gitnew reponame | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment