Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Created October 18, 2019 01:16
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 mrlesmithjr/9da967579f59f55b2ea30ed913a122b4 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/9da967579f59f55b2ea30ed913a122b4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import subprocess
from git import Repo
working_dir = os.getcwd()
repo = Repo(working_dir)
origin_branches = list()
old_branches = list()
branches = list()
for ref in repo.git.branch('-r').split('\n'):
branch = ref.strip()
if branch.startswith('old/'):
old_branches.append(branch.replace('old/', ''))
elif branch.startswith('origin/'):
origin_branches.append(branch.replace('origin/', ''))
for old_branch in old_branches:
if old_branch not in origin_branches:
subprocess.call(['git', 'checkout', f'old/{old_branch}'])
subprocess.call(['git', 'switch', '-c', old_branch])
subprocess.call(['git', 'push'])
else:
if old_branch != 'master':
subprocess.call(['git', 'push', '-d', 'old', old_branch])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment