Skip to content

Instantly share code, notes, and snippets.

@thomas-rooty
Created October 6, 2022 09:56
Show Gist options
  • Save thomas-rooty/bad9034a00546c0c0a361dea7ace50ee to your computer and use it in GitHub Desktop.
Save thomas-rooty/bad9034a00546c0c0a361dea7ace50ee to your computer and use it in GitHub Desktop.
Allows you to rebase all branches onto master at once
# Get all branches from a GitHub repo
# and rebase them on top of master
import subprocess
def get_branches():
branches = []
p = subprocess.Popen(['git', 'branch', '-r'], stdout=subprocess.PIPE)
for line in p.stdout:
line = line.decode('utf-8')
if 'origin/master' in line:
continue
branches.append(line.split()[0].split('/')[1])
return branches
def rebase(branch):
print('Rebasing branch: {}'.format(branch))
subprocess.call(['git', 'checkout', branch])
subprocess.call(['git', 'rebase', 'master'])
def main():
branches = get_branches()
for branch in branches:
rebase(branch)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment