Skip to content

Instantly share code, notes, and snippets.

@prendradjaja
Last active May 17, 2017 21:07
Show Gist options
  • Save prendradjaja/57fd6ee273e5e76210d089f93e96aebb to your computer and use it in GitHub Desktop.
Save prendradjaja/57fd6ee273e5e76210d089f93e96aebb to your computer and use it in GitHub Desktop.
Helper for putting repos on GitHub and Bitbucket
import sys
import os
assert len(sys.argv) == 3
raw_url = sys.argv[2]
class FORMATS:
BITBUCKET = 'https://bitbucket.org'
GITHUB = 'https://github.com'
def fix(raw_url, format):
"""
>>> fix('https://bitbucket.org/prendradjaja/foo', \
FORMATS.BITBUCKET)
'https://[email protected]/prendradjaja/foo.git'
>>> fix('https://github.com/prendradjaja/foo', \
FORMATS.GITHUB)
'https://github.com/prendradjaja/foo.git'
"""
if format == FORMATS.BITBUCKET:
_, _, _, user, repo = raw_url.split('/')
return 'https://{user}@bitbucket.org/{user}/{repo}.git'.format(**{
'user': user,
'repo': repo })
elif format == FORMATS.GITHUB:
_, _, _, user, repo = raw_url.split('/')
return 'https://github.com/{user}/{repo}.git'.format(**{
'user': user,
'repo': repo })
else:
print('Whatcha doin')
exit(1)
if raw_url.startswith(FORMATS.BITBUCKET):
url = fix(raw_url, FORMATS.BITBUCKET)
elif raw_url.startswith(FORMATS.GITHUB):
url = fix(raw_url, FORMATS.GITHUB)
else:
print('Failed: URL format not recognized. URL should start with one of:')
all_prefixes = (getattr(FORMATS, attr) for attr in dir(FORMATS)
if not attr.startswith('_'))
for each in all_prefixes:
print(each)
exit(1)
os.system('git remote add origin {} && git push -u origin master'.format(url))

You know how when you want to put something on GitHub it tells you to copy some commands like:

git remote add origin https://github.com/prendradjaja/foo.git
git push -u origin master

If you're like me and you're SO lazy that you don't want to use your mouse to copy commands, you can just copy the URL (e.g. https://github.com/prendradjaja/foo) in your browser and then use:

git-import.py https://github.com/prendradjaja/foo

Put this in your .bashrc for maximum laziness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment