Skip to content

Instantly share code, notes, and snippets.

@jarkkojs
Created March 26, 2022 09:52
Show Gist options
  • Save jarkkojs/d9246534486fb2d883fe1f040e01144c to your computer and use it in GitHub Desktop.
Save jarkkojs/d9246534486fb2d883fe1f040e01144c to your computer and use it in GitHub Desktop.
# Copyright (C) Jarkko Sakkinen 2022
#!/usr/bin/env python3
import re
import sys
from git.repo import Repo
if __name__ == "__main__":
repo = Repo(sys.argv[1])
# Fetch origin.
remote = repo.remote()
remote.fetch()
heads = list(
filter(lambda h: re.search("^(build|feat|fix|refactor)/", h.name),
repo.heads))
references = list(
filter(
lambda r: re.search("^origin/(build|feat|fix|refactor)/", r.name),
repo.remote().refs))
repo.git.checkout('main')
for head in heads:
print("Deleting " + head.name)
repo.delete_head(head)
for reference in references:
topic = reference.name.split('/', 1)[1]
print("Recreating " + topic)
repo.git.checkout(topic)
repo.git.checkout('main')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment