Skip to content

Instantly share code, notes, and snippets.

@beveradb
Created March 28, 2022 21:53
Show Gist options
  • Save beveradb/1c7b00bb1459d51389a574307df944a0 to your computer and use it in GitHub Desktop.
Save beveradb/1c7b00bb1459d51389a574307df944a0 to your computer and use it in GitHub Desktop.
Grep the git history for a batch of repos in bulk, to see if a string has ever been referenced in any of the repos
#!/bin/bash
# Usage: gitsearch.sh stringToSearchFor *
#
# If you have a lot of repos to search, you might want to run this in a tmux session and pipe the results into a logfile with tee, e.g.
#
# cd folderWithLotsOfReposInIt
# gitsearch.sh stringToSearchFor * | tee /tmp/gitsearch-stringToSearchFor.log
#
expression=$1
shift
echo ${expression}
for repo in "$@"
do
if [ -d ${repo} ]
then
echo "Searching ${repo}"
cd ${repo}
git rev-list --all | xargs git --no-pager grep "${expression}"
cd - > /dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment