Become a Git Branch Curator: From Simple Lists to Provenance Archaeology
“A commit is a brush-stroke; a branch is the canvas where it lives.”
Whether you just want to peek at the branches cluttering your repo or you need museum‑grade provenance for an enterprise audit, this post is your four‑level branch‑discovery palette. Start with the Basic swatch or blend all tiers to wield Git like a true version‑control artist‑scientist.
🟢 1 · BASIC — “Where are my canvases?”
Goal | One‑liner | Shows |
---|---|---|
List local branches | git branch |
Names under .git/refs/heads/
|
Add last‑commit info | git branch -v |
Branch + commit hash + subject |
Include remotes | git branch -a |
Adds .git/refs/remotes/*
|
Quick touch‑up: git branch -vv
also displays each branch’s upstream.
🟡 2 · MEDIUM — “Which ones did I paint?”
Git lacks an explicit “branch creator,” but the root commit (first commit on the branch) holds the author’s signature.
# List local branches whose root commit author == you
git for-each-ref --format='%(authorname): %(refname:short)' --sort=creatordate refs/heads/ | grep -i "$(git config user.name)"
Palette breakdown
-
for-each-ref
— walks every ref -
%(authorname)
— root commit’s author -
%(refname:short)
— nice branch name -
grep
— filters to youruser.name
Remote branches? Repeat with
refs/remotes/
once you’ve pushed withgit push -u
.
🔵 3 · ADVANCED — “Time‑lapse of creation events”
Every git checkout -b new-branch
writes a line to the reflog. Mine that log for a definitive creation diary:
git reflog show --all --date=short | grep 'branch: Created' | awk '{print $1, $6}' | sort -u
Piece | Purpose |
---|---|
--all |
Walks every reflog (HEAD + branches) |
branch: Created |
Pattern Git logs on branch birth |
awk '{print $1, $6}' |
Prints <date> <branch>
|
sort -u |
De‑dupes the list |
Make it permanent
git config --global alias.br-born "reflog show --all --date=short | grep 'branch: Created' | awk '{print \$1, \$6}' | sort -u"
Now git br-born
gives you a one-command scrapbook.
🟣 4 · EXPERT — “Gallery‑grade provenance”
1. Cross‑reference author, reflog and PR metadata
#!/usr/bin/env bash
me="$(git config user.email)"
git for-each-ref --format='%(refname:short)' refs/heads/ |
while read br; do
first=$(git log --reverse --pretty='%h|%an|%ae|%ad|%s' "$br" | head -1)
IFS='|' read h an ae ad msg <<<"$first"
if [[ "$ae" == "$me" ]]; then
printf '%-20s %s %s %s\n' "$br" "$ad" "$an" "$msg"
fi
done
Outputs: branch | date-created | your‑name | initial‑commit‑msg
2. Hosting‑platform archaeology
# GitHub example (requires GitHub CLI)
gh repo view owner/repo --json pullRequests --jq '.pullRequests.nodes[].headRefName'
3. Raw‑object spelunking
Use git cat-file --batch
to stream commit objects, count parents, and identify orphan roots (branch starts) authored by you—perfect for massive mono‑repos.
“Curator” — one alias to rule them all
git curator() {
git br-born || git for-each-ref --format='%(refname:short)' refs/heads/
}
Add to .bashrc
/.zshrc
. If reflog analysis is unavailable, it falls back to a simple list.
Key takeaways (hang these in your gallery)
- Basic → Surface everything that exists.
- Medium → Attribute the artist.
- Advanced → Timestamp the moment of creation.
- Expert → Automate & cross‑verify for audit‑proof provenance.
✍️ Written by: Cristian Sifuentes – Full-stack dev crafting scalable apps with [NET - Azure], [Angular - React], Git, SQL & extensions. Clean code, dark themes, atomic commits
Master this four‑tier palette and you’ll treat branches like pigments—catalogued, timestamped, and signed—ready for any Git exhibition.
Happy version‑painting! 🖌️
Top comments (0)