My posts are usually notes and reference materials for myself, which I publish here with the hope that others might find them useful.
Requires the jq
command-line JSON processor utility, here called using npx
.
Replace <username>
with your GitHub username and be prepared to enter your GitHub password on the command line.
If you have more than 100 repositories, you'll need to run this command several times, editing the page=?
parameter each time.
curl --silent --user "<username>" "https://api.github.com/user/repos?page=1&per_page=100" | npx jq '.[].ssh_url' | while read repo
do
repo="${repo%\"}"
repo="${repo#\"}"
echo "$repo"
done
This nonsense repo="${repo%\"}"
strips the leading and trailing double-quotes "
from the line.
If you want the git://
or https://
schemes instead of SSH, then in the jq
query, replace ssh_url
with git_url
or clone_url
.
To save the output to a text file, append a redirect to the end, as in:
...
echo "$repo"
done > output.txt
Top comments (2)
Had to do some simple edits for terminal execution (and add
/users/
to the URL):Also omitted the username password request, but that's for generally faster usage. :)
Thanks for sharing!
I love the git API. Don't use it much, but it can be very useful.
Also could just do
echo ${repo//\"/}
, assuming there are no quotes on the URI/