{"meta":{"title":"Programmatically importing repositories","intro":"You can programmatically import repositories to GitHub.","product":"Migrations","breadcrumbs":[{"href":"/en/enterprise-cloud@latest/migrations","title":"Migrations"},{"href":"/en/enterprise-cloud@latest/migrations/overview","title":"Overview"},{"href":"/en/enterprise-cloud@latest/migrations/overview/programmatically-importing-repositories","title":"Programmatic repository imports"}],"documentType":"article"},"body":"# Programmatically importing repositories\n\nYou can programmatically import repositories to GitHub.\n\n## About programmatic import of repositories\n\nIn the following guide, you can learn how to programmatically run \"source and history\" migrations of Git repositories to GitHub. Different options are available depending on where the repository is stored.\n\nTo learn more about \"source and history\" and other types of migrations, see [Planning your migration to GitHub](/en/enterprise-cloud@latest/migrations/overview/planning-your-migration-to-github).\n\nThe term \"source repository\" refers to the repository you're importing, and \"imported repository\" refers to the new repository you're creating.\n\n## Using forks\n\nIf the source repository is on GitHub, you may be able to use a fork instead of importing the repository. Forks let you make changes to a project without affecting the original repository, also known as the \"upstream\" repository.\n\nAfter you fork a repository, you can:\n\n* Fetch updates from the upstream repository to keep your fork up to date\n* Contribute back to the original project by creating pull requests from your fork\n  For more information, see [Forks](/en/enterprise-cloud@latest/pull-requests/reference/forks).\n\nYou can programmatically fork a repository using the REST API. For more information, see [REST API endpoints for forks](/en/enterprise-cloud@latest/rest/repos/forks).\n\nIf your use case meets any of the following criteria, you can't use forking instead of directly importing your repository.\n\n* You want the imported repository to be owned by the same user or organization as the source repository.\n* You want one user or organization to be able to import the same source repository multiple times.\n\n## Using repository templates\n\nIf the source repository is on GitHub, you may be able to use repository templates. You can create a template from an existing repository. Anyone with access to the template repository can create a new repository based on the template with the same directory structure, branches, and files. For more details, see [Creating a template repository](/en/enterprise-cloud@latest/repositories/creating-and-managing-repositories/creating-a-template-repository).\n\nTo use repository templates, you must either have read access to an existing repository that's a template, or you must have access to create a template.\n\nYou can programmatically create a repository from a repository template using the REST API. For more information, see [REST API endpoints for repositories](/en/enterprise-cloud@latest/rest/repos/repos).\n\n## Using GitHub Enterprise Importer\n\nIf the source repository is hosted on GitHub, GitHub Enterprise Server, Azure DevOps Services, Bitbucket Server, or Bitbucket Data Center, you can import the repository using GitHub Enterprise Importer. For more information, see [About GitHub Enterprise Importer](/en/enterprise-cloud@latest/migrations/using-github-enterprise-importer/understanding-github-enterprise-importer/about-github-enterprise-importer).\n\nIn addition to your source and version control history, GitHub Enterprise Importer also migrates issues, pull requests, settings, and more.\n\nTo use GitHub Enterprise Importer, you must have admin access to the source repository.\n\nYou can programmatically import repositories with GitHub Enterprise Importer using the GraphQL API.\n\n## Using the Git CLI\n\nIf the source repository is a Git repository, you can call the Git CLI programmatically from your code. You can programmatically create a repository using GitHub's REST API, then use commands like `git clone` and `git push` to import the repository to GitHub.\n\nHow you call the Git CLI differs depending on your code's language. For example, in Node.js, you can use the `child_process` module, or in Ruby, you can use the `open3` module. For more information, see [Child process](https://nodejs.org/api/child_process.html) in the Node.js documentation or the [ruby/open3 repository](https://github.com/ruby/open3) on GitHub.\n\nTo use the Git CLI, you must have access to install Git on the system that hosts your application. For more information, see [Getting Started - Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) in the Git documentation.\n\n## Using GitHub CLI\n\nIf the source repository is a Git repository, you can call the GitHub CLI programmatically from your code. You can use `gh repo create` to create a repository. For more information, see [About GitHub CLI](/en/enterprise-cloud@latest/github-cli/github-cli/about-github-cli).\n\n## Further reading\n\n* [REST API endpoints for repositories](/en/enterprise-cloud@latest/rest/repos/repos)"}