Last active
February 24, 2020 12:52
-
-
Save cuotos/e868eac6c473e278df76cb8c0ddb7bfa to your computer and use it in GitHub Desktop.
find local git branches that do not exist on remote
This file contains 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 subprocess | |
try: | |
branches = subprocess.check_output(['git', 'branch', '-a']).splitlines() | |
except subprocess.CalledProcessError as e: | |
quit(e.returncode) | |
def filter_branches(branches): | |
branches = map(lambda l: l[1:].strip() if l.startswith("*") else l.strip(), branches) | |
branches = filter(lambda line: "remotes/origin/HEAD ->" not in line, branches) | |
return branches | |
def split_branches(branches): | |
local_branches = [] | |
remote_branches = [] | |
for b in branches: | |
if b.startswith("remotes/origin/"): | |
remote_branches.append(b[len("remotes/origin/"):]) | |
else: | |
local_branches.append(b) | |
return local_branches, remote_branches | |
local, remote = split_branches(filter_branches(branches)) | |
missing_branches = [b for b in local if b not in remote] | |
if len(missing_branches) > 0: | |
print("\n".join(missing_branches)) | |
else: | |
print("no missing branches") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment