I have a company GitHub account and I want to back up all of the repositories within, accounting for anything new that might get created for purposes of automation. I was hoping something like this:
git clone git@github.com:company/*.git
or similar would work, but it doesn't seem to like the wildcard there.
Is there a way in Git to clone and then pull everything assuming one has the appropriate permissions?
I created a sample batch script. You can download all private/public repositories from github.com. After a repository is downloaded, it is automatically converted to a zip file.
Note: files.txt file should contain only repository names like:
The prevailing answers here don't take into account that the Github API will only return a maximum of 100 repositories despite what you may specify in
per_page
. If you are cloning a Github org with more than 100 repositories, you will have to follow the paging links in the API response.I wrote a CLI tool to do just that:
This will clone all repositories in the
myorg
organization to the current working directory.On Windows and all UNIX/LINUX systems, using Git Bash or any other Terminal, replace
YOURUSERNAME
by your username and use:Set
CNTX=users
andNAME=yourusername
, to download all your repositories. SetCNTX=orgs
andNAME=yourorgname
, to download all repositories of your organization.The maximum page-size is 100, so you have to call this several times with the right page number to get all your repositories (set
PAGE
to the desired page number you want to download).Here is a shell script that does the above: https://gist.github.com/erdincay/4f1d2e092c50e78ae1ffa39d13fa404e
Organisation repositories
To clone all repos from your organisation, try the following shell one-liner:
User repositories
Cloning all using Git repository URLs:
Cloning all using Clone URL:
Here is the useful shell function which can be added to user's startup files (using
curl
+jq
):Private repositories
If you need to clone the private repos, you can add Authorization token either in your header like:
or pass it in the param (
?access_token=TOKEN
), for example:Notes:
type=private
into your query string.hub
after configuring your API key.See also:
Hints:
- To increase speed, set number of parallel processes by specifying
-P
parameter forxargs
(-P4
= 4 processes).- If you need to raise the GitHub limits, try authenticating by specifying your API key.
- Add
--recursive
to recurse into the registered submodules, and update any nested submodules within.I don't think it's possible to do it that way. Your best bet is to find and loop through a list of an Organization's repositories using the API.
Try this:
http://${GITHUB_BASE_URL}/api/v3/orgs/${ORG_NAME}/repos?access_token=${ACCESS_TOKEN}
ssh_url
property.git clone
each of thosessh_url
s.It's a little bit of extra work, but it's necessary for GitHub to have proper authentication.
To clone only private repos, given an access key, and given python 3 and requests module installed: