Skip to content

Instantly share code, notes, and snippets.

@schtibe
Last active December 23, 2016 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schtibe/15cfe6a2612c08744fc21072334d26cb to your computer and use it in GitHub Desktop.
Save schtibe/15cfe6a2612c08744fc21072334d26cb to your computer and use it in GitHub Desktop.
#!/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