gitgithub

Identify all repositories which just have a master branch


We have a large number of repositories maintained in our Github account. Is there a way to retrieve all repos which are defaulting and just have a master branch


Solution

  • You can write a script and check default branch. For example:

    $ curl -s 'https://api.github.com/users/<username>/repos?per_page=1000' | grep 'default_branch'
    "default_branch": "master"
    # ..
    # ..
    # ..
    

    This will print the default branch name. You can then filter out only relevant repos and have something like:

    repos=$(...)
    echo "$repos" | while read line ; do
       git clone "$line"
    done