github-org-repos-sync

A command-line tool to efficiently sync all repositories from a GitHub organization to your local machine. Perfect for developers who need to maintain local copies of multiple repositories for backup, analysis, or bulk operations.
Features
- Bulk Repository Sync: Clone or update all repositories from a GitHub organization in one command
- Smart Updates: Automatically switches to default branch and pulls latest changes
- Dirty Repository Handling: Safely stashes uncommitted changes before updating
- Parallel Processing: Configurable concurrency for faster synchronization
- Repository Filtering: Include/exclude specific repositories by name pattern
- Archived Repository Support: Option to skip archived repositories
- Permission Aware: Automatically skips repositories without pull permissions
- Empty Repository Handling: Gracefully handles empty repositories without errors
Installation
Download Pre-built Binaries
Download the latest release for your platform from the releases page.
Build from Source
-
Clone the repository:
git clone git@github.com:xbglowx/github-org-repos-sync.git
cd github-org-repos-sync
-
Build the binary:
go build .
Optional: Build with version from git:
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
go build -ldflags "-X github.com/xbglowx/github-org-repos-sync/cmd.Version=$VERSION" .
Optional: Build with custom version:
go build -ldflags "-X github.com/xbglowx/github-org-repos-sync/cmd.Version=1.0.0" .
Prerequisites
Authentication
-
GitHub Personal Access Token: Create a token with repo scope
export GITHUB_TOKEN=<your-token>
-
Git CLI Authentication: Ensure git is authenticated with GitHub (SSH keys or credential helper)
Usage
Basic Syntax
./github-org-repos-sync <organization> -d <destination-path> [options]
Examples
Sync all repositories from an organization
./github-org-repos-sync myorg -d ~/repos/myorg
Sync with custom parallelism (faster for large organizations)
./github-org-repos-sync myorg -d ~/repos -p 5
Skip archived repositories
./github-org-repos-sync myorg -d ~/repos --skip-archived
Filter repositories (include only those containing "api")
./github-org-repos-sync myorg -d ~/repos --include "api"
Exclude specific repositories (skip test repos)
./github-org-repos-sync myorg -d ~/repos --exclude "test"
Backup an entire organization
./github-org-repos-sync mycompany -d ~/backups/mycompany-repos
Sync only service repositories
./github-org-repos-sync mycompany -d ~/services --include "service"
Show help
./github-org-repos-sync --help
Check version
# Using version subcommand
./github-org-repos-sync version
# Using version flag
./github-org-repos-sync --version
./github-org-repos-sync -v
How It Works
- Repository Discovery: Fetches a list of all repositories in the specified organization that you have access to
- Local Check: Determines if each repository already exists locally
- Clone or Update:
- New repositories: Clones them to the destination path
- Existing repositories:
- Fetches latest changes from remote
- Stashes uncommitted changes if the working directory is dirty
- Switches to the repository's default branch
- Pulls latest changes with rebase
- Parallel Processing: Processes multiple repositories concurrently for improved performance
- Error Handling: Gracefully handles edge cases like empty repositories, missing branches, and permission issues
Command Line Options
| Flag |
Description |
Default |
-d, --dest |
Destination directory for repositories |
Required |
-p, --parallelism |
Number of concurrent operations |
10 |
--skip-archived |
Skip archived repositories |
false |
--include |
Include only repositories containing this string |
"" |
--exclude |
Exclude repositories containing this string |
"" |
-h, --help |
Show help message |
- |
Troubleshooting
Permission Issues
- Ensure your GitHub token has
repo scope
- Verify you have access to the organization
- Check that git CLI is properly authenticated
Network Issues
- The tool will retry failed operations
- Use lower parallelism (
-p 1) for unstable connections
Large Organizations
- Consider using filters (
--include/--exclude) for large organizations
- Monitor disk space when syncing many repositories
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.