Last active
June 12, 2017 14:49
-
-
Save josemigallas/4e4d9745b7173bf0838815c8a017bfa3 to your computer and use it in GitHub Desktop.
This script clones a repository from Github, previously forked, and add both remotes origin and upstream, renaming origin with your username.
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
#!/usr/bin/python | |
import sys | |
from os.path import splitext, basename | |
from os import system | |
import re | |
# Verify arguments | |
try: | |
urlForked = sys.argv[1] | |
urlUpstream = sys.argv[2] | |
except Exception: | |
print "Usage: git-clone <origin> <upstream>" | |
sys.exit(1) | |
repoName = splitext(basename(urlUpstream))[0] | |
userName = re.search(r'\D*github.com[/:]([^/?]+)', urlForked).group(1) | |
bashCommand = ''' | |
git clone {0} {1} | |
( | |
cd {1} | |
git remote rename origin {2} | |
git remote add upstream {3} | |
) | |
'''.format(urlForked, repoName, userName, urlUpstream) | |
system(bashCommand) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment