Add support for rename repository when creating a fork from API

Would be great if we could rename repository when creating a fork via API it would help the hub cli along



Hi @casz,

Thanks for being here! And thank you for taking the time to provide this feedback I’ve taken your suggestion and passed it along to the appropriate teams. In the meanwhile, have you checked out this new Open Source Project Might be of interest :slight_smile:

The problem:

I have  I want to use the github REST API/hub fork to fork - same name as a project I currently have, but completely unrelated.  If I use hub fork I get this:

$ hub fork
Error creating fork: richm/projectA already exists on

The API uses POST and allows you to provide an organization parameter:

organization string Optional parameter to specify the organization name if forking into an organization.

Perhaps it would be easy to add a name parameter which is the name for the new repo?

name string Optional parameter to specify the name of the new repo.

Then I could use e.g.

hub fork --reponame some-org-projectA to create

As of April 12, 2022, the GitHub web UI supports naming forks (blog post).

Are there any plans to support this via the REST API (given forking repos via the GraphQL API is not supported yet)?

The current workflow to fork and rename a repo requires quite a bit of additional work because forking a repo is asynchronous. In summary, this is what is needed:

  1. Call the POST /repos/{owner}/{repo}/forks endpoint
  2. Store the forked repo name in a database
  3. Run a cron job to wait for the forking process to complete
  4. Call the PATCH /repos/{owner}/{repo} endpoint to rename the forked repo

The above could be reduced to a single POST /repos/{owner}/{repo}/forks call if naming the fork were supported.