renamegithub-api

Rename a file with github api?


I thought that the update file method of the Github API could be used to rename a file (by providing the new path as parameter) but it does not seem to work.

The only way to rename is to delete the file and to create a similar one with the new name?


Solution

  • I thought that the update file method of the Github API could be used to rename a file (by providing the new path as parameter) but it does not seem to work.

    There's no way to rename a file with a single request to the API.

    The only way to rename is to delete the file and to create a similar one with the new name?

    That's one way, but the downside is that you get two commits in the history (one for the delete, and one for the create).

    A different way is to use the low-level Git API:

    https://developer.github.com/v3/git/

    With that, you can modify the tree entry containing the blob to list it under a different name, then create a new commit for that tree, and finally update the branch to point to that new commit. The whole process requires more API requests, but you get a single commit for the rename.