Last active
December 23, 2016 11:40
-
-
Save schtibe/15cfe6a2612c08744fc21072334d26cb to your computer and use it in GitHub Desktop.
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/env python | |
import sys | |
from plumbum.cmd import git | |
from termcolor import cprint | |
try: | |
new_branch = sys.argv[1] | |
except IndexError: | |
print("Provide a branch name!", file=sys.stderr) | |
sys.exit(1) | |
print("which branch to you want to use?") | |
branches = git('branch', '-a').split('\n') | |
assigns = zip(range(0, len(branches)), branches) | |
default = 0 | |
for a in assigns: | |
number = a[0] | |
name = a[1] | |
if name.startswith('*'): | |
cprint("{}: {}".format(number, name), 'red') | |
elif 'upstream/master' in name: | |
default = number | |
cprint("{}: {}".format(number, name), 'green') | |
else: | |
print("{}: {}".format(number, name)) | |
print() | |
number = input("Which branch do you want to fork from ({}) ".format(default)) | |
selected_branch = int(number if number else default) | |
git('checkout', | |
'-b', | |
new_branch, | |
branches[selected_branch].replace("*", "").strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment