Skip to content

Instantly share code, notes, and snippets.

@bradmontgomery
Last active March 13, 2026 03:11
Show Gist options
  • Select an option

  • Save bradmontgomery/11c9bc92e22505dfc2513e24791892d1 to your computer and use it in GitHub Desktop.

Select an option

Save bradmontgomery/11c9bc92e22505dfc2513e24791892d1 to your computer and use it in GitHub Desktop.
gitls — like ls, but for git repos.

gitls — like ls, but for git repos.

Install it:

bashchmod +x gitls sudo mv gitls /usr/local/bin/gitls

Usage:

bashgitls # searches current directory gitls ~/projects # searches a specific directory

Example output:

api-service                              on  main
frontend/dashboard                       on  feature/dark-mode
infra/terraform                          on  staging

3 repo(s) found

Features:

  • Recursively walks directories using find
  • Falls back gracefully — if on a detached HEAD, shows the tag or short SHA instead of crashing
  • Accepts an optional path argument
  • Color-coded output (repo path in cyan, branch in green)
  • Summary count at the end
#!/usr/bin/env bash
# gitls - recursively find git repos and display their current branch
# Usage: gitls [directory] (defaults to current directory)
set -euo pipefail
ROOT="${1:-.}"
BOLD="\033[1m"
CYAN="\033[36m"
GREEN="\033[32m"
YELLOW="\033[33m"
RESET="\033[0m"
DIM="\033[2m"
found=0
while IFS= read -r gitdir; do
repo_dir="$(dirname "$gitdir")"
branch=$(git -C "$repo_dir" symbolic-ref --short HEAD 2>/dev/null \
|| git -C "$repo_dir" describe --tags --exact-match HEAD 2>/dev/null \
|| git -C "$repo_dir" rev-parse --short HEAD 2>/dev/null \
|| echo "(unknown)")
rel_path="${repo_dir#$ROOT}"
rel_path="${rel_path#/}"
[ -z "$rel_path" ] && rel_path="."
printf "${BOLD}${CYAN}%-40s${RESET} ${DIM}on${RESET} ${GREEN}%s${RESET}\n" "$rel_path" "$branch"
(( found++ )) || true
done < <(find "$ROOT" -type d -name ".git" 2>/dev/null | sort)
if (( found == 0 )); then
printf "${YELLOW}No git repositories found under:${RESET} %s\n" "$ROOT"
else
printf "\n${DIM}%d repo(s) found${RESET}\n" "$found"
fi
@bradmontgomery
Copy link
Author

Because now LLM's let me work on a bunch of different things like a squirrel hopped up on caffeine -- with a memory to match!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment