iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏷

Cloning GitHub labels from another repository using GitHub CLI

に公開

I recently had an opportunity to migrate GitHub Issues to another repository, but since the labels associated with the issues were not inherited, I decided to clone them from the source repository.

Installing the GitHub CLI

Cloning labels is done using the GitHub CLI.

https://github.com/cli/cli

Install the GitHub CLI using the command described in the documentation.

% brew install gh

Run the following command if an update is needed.

% brew upgrade gh

Authenticating Your GitHub Account

After installing the GitHub CLI, authenticate your GitHub account.
https://cli.github.com/manual/gh_auth_login

Start the authentication flow with the following command.

% gh auth login

Answer the questions required for authentication.

? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

Finally, a one-time code will be issued, so copy and paste it into the GitHub screen opened in your browser.

! First copy your one-time code: xxxx-xxxx
Press Enter to open github.com in your browser... 
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as unsolublesugar

Once authentication is successfully completed, you will be able to use GitHub CLI commands.

Refer to the manual for details on available commands and options.
https://cli.github.com/manual/

Cloning Labels with gh label

Use the gh label command for label-related operations.

  • gh label clone
  • gh label create
  • gh label delete
  • gh label edit
  • gh label list

For example, you can list the labels in a GitHub repository. Of course, creating, deleting, and editing are also possible.

% gh label list -R OWNER/REPO

Showing 10 of 10 labels in OWNER/REPO

bug               Something isn't working                     #d73a4a
documentation     Improvements or additions to documentation  #0075ca
duplicate         This issue or pull request already exists   #cfd3d7
enhancement       New feature or request                      #a2eeef
good first issue  Good for newcomers                          #7057ff
help wanted       Extra attention is needed                   #008672
invalid           This doesn't seem right                     #e4e669
question          Further information is requested            #d876e3
wontfix           This will not be worked on                  #ffffff
refactor-devops   refactoring or DevOps-related               #82D694

To clone labels from REPO-A to another repository REPO-B, simply run the following command:

 % gh label clone OWNER/REPO-A -R OWNER/REPO-B
✓ Cloned 10 labels from OWNER/REPO-A to OWNER/REPO-B

By cloning labels in advance, labels with the same name will be inherited during the issue migration. If you have already organized labels in a repository you are currently using, it seems like a good idea to port them over using gh label clone.

https://zenn.dev/unsoluble_sugar/articles/930c056d301dea

Discussion