Find the last Git branches that you were working on.
Here’s a quick script that prints the most recent branches you were working on, since I find myself needing to lswitching across multiple branches frequently.
#!/usr/bin/env python
# git-r prints the last local branches that were checked out in git.
# This is useful if you want to find the last branch that you were working on.
import subprocess
import sys
seen = set()
lines = []
output = subprocess.check_output("git log -g --oneline --decorate-refs='refs/heads' --pretty=format:'%d: %s' -100", shell=True)
for l in output.split("\n"):
if not l.startswith(" ("):
continue
if l in seen:
continue
seen.add(l)
lines.append(l)
print("\n".join(lines))