Create Clone Commands for all Repositories on a GitHub page

This post talks about how you can create git clone links for all the repositories from a GitHub page.

Creating a list of clone commands from a list of Repositories

To run this code to create the list of commands you need to open your browsers console window.

On Chrome you can press Ctrl-Shift-J
On Firefox you can press F12

Once the console is open, paste in the following command into the console.

gitCloneCommands=[];
document.querySelectorAll("a[itemprop='name codeRepository']").forEach(
   function(a) { gitCloneCommands.push("git clone " + a.href); }
);
console.log(gitCloneCommands.join("\r\n"))

This will print out several lines of text, each with a git clone command which can be run in your console.

If you need to tweak the clone command you just need to modify the central function:

function(a) { gitCloneCommands.push("git clone " + a.href); }

The value of a.href will always be the HTTPS link to the repository which can be changed as needed.

This relies on the current structure of the GitHub webpage. If this changes and no longer works leave a comment and I will have another look and update it.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.