Github List All Repositories in Organization or Personal using REST API

I have been trying to get the complete list of Repositories private and public in my github account ( user + Organization ) using GITHUB rest api

I had to create a CSV report of  All repositories in a specific format like shown below.

Github list all repositories

I have done similar thing earlier with bitbucket and the script is available here for your reference

Before we go to the script some background on the script and the prerequisites.



  • JQ - Json parser
  • Linux ( Mac is fine ) with following commands available
    • awk
    • sed
    • bash
    • curl
    • tr
  • permission to create and run a script and a temp file


How to use the script

Copy the script code and paste it into your editor like vi/nano/code etc and save it with .sh extension.

My preferred name for this script is

Set it to executable permission with some command like

chmod a+x

Update the script with your corresponding details such as org name, token, username etc

Then Run the script and redirect the output to a CSV file name of your choice

./ > Output.csv


Script to List All repositories in Github using REST API

Here is the shell script that uses all the aforementioned linux commands along with curl and jq parser to create a neat CSV report of All repositories.

# Author: Sarav AK
# Email: [email protected]
# Created Date: 19 Aug 2021


# No of reposoitories per page - Maximum Limit is 100

# Change the BASEURL to  your Org or User based
# Org base URL

# User base URL
# BASEURL="<your_github_username>/repos"

# Calculating the Total Pages after enabling Pagination
TOTALPAGES=`curl -I -i -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s ${BASEURL}\?per_page\=${PERPAGE} | grep -i link: 2>/dev/null|sed 's/link: //g'|awk -F',' -v  ORS='\n' '{ for (i = 1; i <= NF; i++) print $i }'|grep -i last|awk '{print $1}' | tr -d '\<\>' | tr '\?\&' ' '|awk '{print $3}'| tr -d '=;page'`


until [ $i -gt $TOTALPAGES ]
  result=`curl -s -u $USERNAME:$TOKEN -H 'Accept: application/vnd.github.v3+json' ${BASEURL}?per_page=${PERPAGE}\&page=${i} 2>&1`
  echo $result > tempfile
  echo "Repo Name, SSH URL, Clone URL"
  cat tempfile|jq '.[]| [.name, .ssh_url, .clone_url]| @csv'|tr -d '\\"'


This can be used for both private and public github repositories

This can be used for both user based accounts and Organization based accounts

All you have to do is to update the necassary details such as

  • username
  • git api token
  • how many repositories to fetch per page ( maximum 100 allowed per page)
  • base api url
    • For Organization Listing
    • For Personal User account Listing



How to create a Personal access or API token in Github

Follow this article from Github for more detailed info on how to create your personal access token

Further customizations and updates

Feel free to fork this script  and add updates

Here is the list of information that github API provides for a Single repository. Hope this help in modifying this script

    "id": 171173763,
    "node_id": "MDEwOlJlcG9zaXRvcnkxNzExNzM3NjM=",
    "name": "SampleWebApp",
    "full_name": "AKSarav/SampleWebApp",
    "private": false,
    "owner": {
      "login": "AKSarav",
      "id": 17838978,
      "node_id": "MDQ6VXNlcjE3ODM4OTc4",
      "avatar_url": "",
      "gravatar_id": "",
      "url": "",
      "html_url": "",
      "followers_url": "",
      "following_url": "{/other_user}",
      "gists_url": "{/gist_id}",
      "starred_url": "{/owner}{/repo}",
      "subscriptions_url": "",
      "organizations_url": "",
      "repos_url": "",
      "events_url": "{/privacy}",
      "received_events_url": "",
      "type": "User",
      "site_admin": false
    "html_url": "",
    "description": "A Sample Web Application with Snoop Servlet for Tomcat, Weblogic, Jboss, Websphere",
    "fork": false,
    "url": "",
    "forks_url": "",
    "keys_url": "{/key_id}",
    "collaborators_url": "{/collaborator}",
    "teams_url": "",
    "hooks_url": "",
    "issue_events_url": "{/number}",
    "events_url": "",
    "assignees_url": "{/user}",
    "branches_url": "{/branch}",
    "tags_url": "",
    "blobs_url": "{/sha}",
    "git_tags_url": "{/sha}",
    "git_refs_url": "{/sha}",
    "trees_url": "{/sha}",
    "statuses_url": "{sha}",
    "languages_url": "",
    "stargazers_url": "",
    "contributors_url": "",
    "subscribers_url": "",
    "subscription_url": "",
    "commits_url": "{/sha}",
    "git_commits_url": "{/sha}",
    "comments_url": "{/number}",
    "issue_comment_url": "{/number}",
    "contents_url": "{+path}",
    "compare_url": "{base}...{head}",
    "merges_url": "",
    "archive_url": "{archive_format}{/ref}",
    "downloads_url": "",
    "issues_url": "{/number}",
    "pulls_url": "{/number}",
    "milestones_url": "{/number}",
    "notifications_url": "{?since,all,participating}",
    "labels_url": "{/name}",
    "releases_url": "{/id}",
    "deployments_url": "",
    "created_at": "2019-02-17T21:19:55Z",
    "updated_at": "2020-11-02T08:11:30Z",
    "pushed_at": "2021-01-18T15:02:45Z",
    "git_url": "git://",
    "ssh_url": "[email protected]:AKSarav/SampleWebApp.git",
    "clone_url": "",
    "svn_url": "",
    "homepage": null,
    "size": 18039,
    "stargazers_count": 1,
    "watchers_count": 1,
    "language": "Java",
    "has_issues": true,
    "has_projects": true,
    "has_downloads": true,
    "has_wiki": true,
    "has_pages": false,
    "forks_count": 42,
    "mirror_url": null,
    "archived": false,
    "disabled": false,
    "open_issues_count": 1,
    "license": null,
    "forks": 42,
    "open_issues": 1,
    "watchers": 1,
    "default_branch": "master"

If you want to add any more fields to the csv like created_at, pushed_at  from the available fields given above.

You can update the array of jq like this, in the script

jq '.[]| [.name, .ssh_url, .clone_url, .created_at, .pushed_at]


Hope this helps and if you have any better ways to do this or written such script in any other language and wants to share with us. please post it in comments.



Sarav AK

Follow me on Linkedin My Profile
Follow DevopsJunction onFacebook orTwitter
For more practical videos and tutorials. Subscribe to our channel

Buy Me a Coffee at

Signup for Exclusive "Subscriber-only" Content