A small toolkit to copy GitHub repository label definitions (name, color, description) from one repository to another. The repository includes three platform-specific scripts with the same behavior and similar command syntax.
| Filename | Platform | Language | Invocation |
|---|---|---|---|
| CopyGitHubLabels.sh | Unix / macOS | Bash | ./CopyGitHubLabels.sh |
| CopyGitHubLabels.py | Cross platform | Python 3 | python3 CopyGitHubLabels.py |
| CopyGitHubLabels.ps1 | Cross platform (Windows/macOS/Linux) | PowerShell 7+ (also works on Windows PowerShell) | Windows: .\CopyGitHubLabels.ps1 • Unix/macOS: ./CopyGitHubLabels.ps1 (run in pwsh) |
.\CopyGitHubLabels.ps1 (Windows)
./CopyGitHubLabels.ps1 (Unix/macOS in pwsh)
.\CopyGitHubLabels.ps1 -SrcOwner myorg -SrcRepo source-repo -DstOwner myorg -DstRepo dest-repo
.\CopyGitHubLabels.ps1 -DryRun
.\CopyGitHubLabels.ps1 -VerboseLogging
./CopyGitHubLabels.sh
./CopyGitHubLabels.sh --src-owner myorg --src-repo source-repo --dst-owner myorg --dst-repo dest-repo
./CopyGitHubLabels.sh --src-owner myorg --src-repo src --dst-owner myorg --dst-repo dst --dry-run
./CopyGitHubLabels.sh --src-owner myorg --src-repo src --dst-owner myorg --dst-repo dst --verbose
python3 CopyGitHubLabels.py
python3 CopyGitHubLabels.py --src-owner myorg --src-repo source-repo --dst-owner myorg --dst-repo dest-repo
python3 CopyGitHubLabels.py --dry-run
python3 CopyGitHubLabels.py --verbose
-
What is copied
The scripts copy label definitions only: name, color, and description for each label defined in the source repository. -
What is not copied
The scripts do not copy which labels are applied to individual issues or pull requests. They do not touch Git tags or commit metadata. -
Interactive prompts and defaults
Each script contains top-of-file defaults you can edit. If a parameter is not supplied on the command line and the corresponding default is empty, the script will prompt you interactively for that value. If you set a non-empty default in the script, that value will be used unless overridden on the command line. -
Update strategy
For each label the scripts attempt to PATCH (update) the destination label first. If the PATCH indicates the label does not exist (HTTP 404 / Not Found), the scripts POST (create) the label in the destination repository. -
Common options
- Dry run: shows the actions the script would take without making changes (
--dry-runfor shell/python,-DryRunfor PowerShell). - Verbose: prints API output for debugging (
--verbosefor shell/python,-VerboseLoggingfor PowerShell).
- Dry run: shows the actions the script would take without making changes (
-
File naming
Filenames use CopyGitHubLabels (no dashes) to match the chosen convention. Keep the extension to indicate the runtime: .sh, .py, .ps1. -
Permissions
Ensure the account used by the gh CLI has permission to read labels in the source repo and create/update labels in the destination repo. -
Noninteractive environments
If you run these scripts in CI or other noninteractive environments, set the top-of-file defaults or pass all required parameters on the command line to avoid prompts. -
Cross-platform PowerShell notes
- Unix/macOS: Make the script executable with
chmod +x CopyGitHubLabels.ps1, then run./CopyGitHubLabels.ps1inpwsh. - Windows: Run with Windows PowerShell (
powershell.exe) or PowerShell 7 (pwsh.exe):.\CopyGitHubLabels.ps1.
- Unix/macOS: Make the script executable with