28

How can I see a list of all the child repos that have been created from my template repo on GitHub?

GitHub displays how many forks were created from a given repo at the top of the WUI, next to the "stars" and "watches." And you can display a list of links to those users' forks under the "analytics" tab.

How can I get a similar list of all the repos that were created from my template repo on GitHub?

2

2 Answers 2

8

Eureka! After reading this - Search based on the contents of a repository, the answer was clear! Search by README.md file content!

Use GitHub's search engine and provide a unique combination of words that appear in your README.md file. This is how I do it for my template - unfor19/terraform-multienv

in:readme sort:updated -user:unfor19 "tfmultienv"
github.com/search?q=in%3Areadme+sort%3Aupdated+-user%3Aunfor19+%22%60tfmultienv%60%22&type=repositories

To get meaningful search results

  • Sorting with sort:updated
  • Filtering out my user name -user:USERNAME with -QUALIFIER.

Instead of hardcoding USERNAME you can use the keyword @me.

2
  • 7
    Of course this generally won't work, as nothing prevents users from nuking the template's README.md and adding their own content; and people usually do. Oct 11, 2020 at 0:56
  • 4
    That's the best alternative I could find. Do you have a better alternative?
    – Meir Gabay
    Oct 11, 2020 at 7:37
3

Shell scripting and gh FTW:

#!/bin/bash

org_name="MYORGNAME"
repo_list=`gh repo list $org_name --limit 1000 | awk '{print $1}'`
template_repo=$1

if [ -z "$template_repo" ]
then
  echo "Usage: $0 <template_repo>"
  echo "  List repositories generated from a given template repository"
  echo "ABORTING!"
  exit 1
fi

echo "Searching for repositories generated from template: $template_repo"
for repo in $repo_list
do
  repo_info=`gh api repos/$repo`
  echo "$repo_info" | jq -r ".template_repository.full_name" | grep "$template_repo" 2>&1 > /dev/null
  if [ "$?" -eq "0" ]
  then
    echo "repo_using_template: $repo"
  fi
done

Then, run ./find_repo_by_template.sh <template_repo> to get a listing of repositories that use that template, AFTER setting the org_name variable. My use case required searching within an organization. If you have a different use case, you should be able to easily tweak my script to get the desired results.

2
  • 1
    So this doesn't work for searching all of GitHub.com (ie all users, not just a specific org)? I have no idea how to tweak this to search all users and all orgs. Can you please update the question with how to do that? May 31 at 13:15
  • This worked perfect for my org!
    – Busch
    Jul 7 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.