Skip to content

Instantly share code, notes, and snippets.

@morufajibike
Last active January 2, 2021 07:06
Show Gist options
  • Save morufajibike/7f8907a85f896567c69c9b3c475cf297 to your computer and use it in GitHub Desktop.
Save morufajibike/7f8907a85f896567c69c9b3c475cf297 to your computer and use it in GitHub Desktop.
Bash one-liner to clone Github repos

Given a list of GitHub URLs in the file gh-repos.txt, like this:

git@github.com:username/first-repository.git
git@github.com:username/second-repository.git
git@github.com:username/third-repository.git

<gh-repos.txt xargs -n1 git clone

Explanation

To run a command for each line of our input, gh-repos.txt, we use xargs -n1.

The tool xargs reads items from input and executes any commands it finds (it will echo if it doesn’t find any).

By default, it assumes that items are separated by spaces; new lines also works and makes our list easier to read.

The flag -n1 tells xargs to use 1 argument, or in our case, one line, per command.

We build our command with git clone, which xargs then executes for each line. Ta-da.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment