Created
November 1, 2019 02:10
-
-
Save mrlesmithjr/40f56683b8da9cc2a8737d48d26b7699 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import os | |
import subprocess | |
from git import Repo | |
working_dir = os.getcwd() | |
repo = Repo(working_dir) | |
origin_branches = list() | |
for ref in repo.git.branch('-r').split('\n'): | |
branch = ref.strip() | |
if branch.startswith('origin/'): | |
if 'HEAD' not in branch and 'master' not in branch: | |
origin_branches.append(branch.replace('origin/', '')) | |
for branch in origin_branches: | |
new_branch = branch.replace('ansible/', '') | |
subprocess.call(['git', 'checkout', branch]) | |
subprocess.call(['git', 'branch', '-m', new_branch]) | |
subprocess.call(['git', 'push', '-d', 'origin', branch]) | |
subprocess.call(['git', 'push', '-u', 'origin', new_branch]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment