Cloning a Repo Externally

I want to clone a GitHub repository into an arbitrarily named repository on my own account without support from the g i t CLI or GitHub UI (i.e. using GitHub Actions programmatically to automatically provision the repository). What are some thoughts on the best way to do this?

Hi – in order to best assist you, could you outline a step-by-step scenario of what you are trying to achieve?

For example, if you have an arbitrary repository named peterzhu08/test, are you hoping to copy all the files and folder structure of another repository verbatim into test?

If we’ve misunderstood, could you kindly clarify and we’ll try to offer some suggestions, thank you!

Hey there github support,

Basically I want to create a UI which I’m doing using React where it asks the user to input the location of a public repository I want to clone and a name for that repository. So if we have a repository in personA/repo1 I want to clone all those items into my own reposioty under a name I put into the UI. It would be all the contents in personA/repo1 in my account with the name I provide it.

I have an authentication and UI working for this - I am littlle bit lost on the backend architecture and I’d like a little help and direction with using github’s API. I’m thinking of a Node.js Express backend as of now.

Currently, I have explored the github v3 REST API which I was successfully able to create a repo using a POST request to Postman. However, I am a bit lost on the best way to create a clone using the REST API. I could not find this in the documentation.

I have also explored the Github v4 GraphQL api and was able to do the same, but again did not find adequate documentation on how to clone another account’s repo onto me own account within the API only.

Any help would be appreciated.

Hi, thank you for providing more context.

It won’t be possible to clone using REST API – sorry about that.

So if we have a repository in personA/repo1 I want to clone all those items into my own reposioty under a name I put into the UI.

Usually we recommend users fork repositories: but if you prefer not to have a fork relationship, it might be a bit more complex.

You could use the contents API to grab all the contents of a file or directory in a repository:

Hey there,

Thanks for the response. I was looking through the Contents API and it seemed like we would need to do this for every file rather than simply doing with with a repository, which makes it pretty low level which is something we want to avoid.

Additionally, to clarify, from the project description, we do not want to fork a repository.

I was looking through the GraphQL v4 API and encountered a cloneProject mutation method. It takes in a cloneProjectInput type which I am having trouble creating. Is there some sample code that can be found using this method, and is this the right appraoch to go down with this API for the purpose I was looking for?