Skip to content

Instantly share code, notes, and snippets.

@kevinmichaelchen
Created August 15, 2014 19:08
Show Gist options
  • Save kevinmichaelchen/3353eeeb1b6d4437ffe4 to your computer and use it in GitHub Desktop.
Save kevinmichaelchen/3353eeeb1b6d4437ffe4 to your computer and use it in GitHub Desktop.
Outputs a Git command to rebase linear feature branches
#! /usr/bin/env python
# input: branches.txt lists feature branches
# branches MUST be on their own line
# branches MUST be ordered NEWEST to OLDEST
# output: the git command to rebase linear branches onto 'develop'
import sys
BRANCH = 'develop'
def main(branch=BRANCH, option='ours'):
f = open('branches.txt')
lines = f.read().splitlines()
f.close()
print lines
print '\n\n\n'
print 'Your command is:'
print ''
command = ''
stop = len(lines) - 1
for i in range(0, stop):
new = lines[i]
old = lines[i+1]
sep = '' if i == stop - 1 else ' && '
s = 'git rebase -s recursive -X ' + option + ' --onto ' + BRANCH + ' ' + old + ' ' + new + sep
command += s
print command
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment