Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created February 6, 2025 16:30
Show Gist options
  • Save mikebridge/bdcc996b3ac807df67aaece8f0c70daf to your computer and use it in GitHub Desktop.
Save mikebridge/bdcc996b3ac807df67aaece8f0c70daf to your computer and use it in GitHub Desktop.
Find a file by name among many git branches
#!/usr/bin/env bash
FILE_NAME_PATTERN="index.ts"
git branch --format="%(refname:short)" | xargs -I {} sh -c 'git ls-tree -r --name-only "{}" | grep -q "${FILE_NAME_PATTERN}" && echo "File exists in {}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment