Created
October 6, 2022 09:56
-
-
Save thomas-rooty/bad9034a00546c0c0a361dea7ace50ee to your computer and use it in GitHub Desktop.
Allows you to rebase all branches onto master at once
This file contains hidden or 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
# 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