Clone GitHub repositories at a time

GIthub clone repository

Using GitHub CLI, you can clone all your repositories at a time. You can also do this using GitHub API and Git. Here, I am following the GitHub CLI step by step.

Install Github CLI: First, you have to install Github CLI on your machine. Follow GitHub CLI installation.

Authenticate with GitHub:

[gh auth login] 

Use this command to log in to your GitHub and follow the instructions. 

Here you can follow the protocol HTTPS to do it easily.

If there is a permission issue with the directory, Follow this:

Change to a Directory with Appropriate Permissions

[ mkdir -p ~/my-github-repos
cd ~/my-github-repos
]

Check ownership and permissions

[ ls -ld ~/my-github-repos ]

Change ownership if needed

[ sudo chown -R $(whoami) ~/my-github-repos ]

Ensure the directory is writable

[ chmod u+rwx ~/my-github-repos ]

List and Clone All Repositories:

[gh repo list USERNAME --limit 100 --json nameWithOwner,sshUrl --jq '.[].sshUrl' | xargs -L1 git clone]

Use the following one-liner to list and clone all your repositories. This command fetches the repository URLs and then clones them. Change the USERNAME with yours. 

Leave a Reply

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