A Python command-line tool that automates the process of cloning all repositories from a GitHub user or organization.
- Complete repository cloning: Clone all repositories from a specified GitHub user or organization
- Smart sync: If a repository is not cloned already, it will be cloned; if it exists, it will be fetched
- Exclusion patterns: Option to exclude specific repositories based on name patterns
- Dry-run mode: List all repositories without actually cloning them
- Flexible destination: Configurable destination path for cloned repositories
- Organization handling: Option to disable root organization/user folder creation
- Enterprise support: Support for GitHub Enterprise instances with custom API URLs
- Robust error handling: Clear error messages and appropriate exit codes
pip install -r requirements.txtpython github-cloner.py [options]Set your GitHub token using one of these methods:
-
Environment variable (recommended):
export GITHUB_TOKEN=your-api-token python github-cloner.py -o myorg -
Command line argument:
python github-cloner.py -o myorg -t your-api-token
| Option | Long Option | Description |
|---|---|---|
-o |
--organization |
GitHub organization to clone from |
-u |
--user |
GitHub user to clone from |
-t |
--token |
GitHub API token (can also use GITHUB_TOKEN env var) |
-p |
--path |
Destination directory (default: current directory) |
-d |
--dry-run |
List repositories without cloning |
-e |
--exclude |
Exclude repositories containing this pattern |
--disable-root |
Don't create organization/user folder | |
--clone-method |
Clone method: https or ssh (default: https) |
|
--url |
GitHub API URL for Enterprise (default: https://api.github.com) |
|
-h |
--help |
Show help message and exit |
Basic usage:
python github-cloner.py -o myorgClone from user:
python github-cloner.py -u usernameClone to specific directory:
python github-cloner.py -o myorg -p /path/to/reposDry run to see what would be cloned:
python github-cloner.py -u username --dry-runExclude archived repositories:
python github-cloner.py -o myorg --exclude archivedClone without creating root folder:
python github-cloner.py -o myorg --disable-rootUse SSH for cloning:
python github-cloner.py -o myorg --clone-method sshUse GitHub Enterprise:
python github-cloner.py -o myorg --url https://github.company.com/api/v3| Code | Description |
|---|---|
| 0 | Success |
| 1 | Execution error |
| 2 | Missing required arguments |
| 10 | Destination path error |
| 20 | Git executable not found |
| 21 | Git clone error |
| 22 | Git fetch error |
| 30 | GitHub API error |
| 40 | Authentication error |
Your GitHub token needs:
- For private repositories:
reposcope - For public repositories only: No special scopes required
Create a token at: https://github.com/settings/tokens
This project is licensed under the MIT License.
Contributions are welcome, please follow the semantic versioning branch naming convention:
- main: Production-ready code
- develop: Integration branch for features
- feat/: New features (
feat/user-authentication) - fix/: Bug fixes (
fix/connection-timeout) - chore/: Maintenance (
chore/update-dependencies)
