Чтобы создать репозиторий GitHub из существующей папки и существующего репозитория, вы можете использовать несколько методов. Вот несколько примеров кода:
-
Метод: использование интерфейса командной строки GitHub
Пример кода:# Clone the existing repository git clone <existing-repo-url> # Navigate to the cloned repository cd <existing-repo-folder> # Create a new repository on GitHub gh repo create <new-repo-name> --public # Push the code to the new repository git remote add origin <new-repo-url> git push -u origin master -
Метод: использование GitHub REST API и cURL.
Пример кода:# Clone the existing repository git clone <existing-repo-url> # Navigate to the cloned repository cd <existing-repo-folder> # Create a new repository on GitHub (using the API) curl -u <username>:<token> -X POST \ -d '{"name":"<new-repo-name>","private":false}' \ https://api.github.com/user/repos # Push the code to the new repository git remote add origin <new-repo-url> git push -u origin master -
Метод: использование GitHub REST API и Python.
Пример кода:import requests # Clone the existing repository # ... # Navigate to the cloned repository # ... # Create a new repository on GitHub (using the API) url = "https://api.github.com/user/repos" headers = { "Authorization": "Token <token>", "Accept": "application/vnd.github.v3+json" } data = { "name": "<new-repo-name>", "private": False } response = requests.post(url, headers=headers, json=data) response_json = response.json() new_repo_url = response_json["html_url"] # Push the code to the new repository # ...
Это всего лишь несколько примеров. Существуют и другие методы и инструменты. Не забудьте заменить , , , , и с соответствующими значениями для вашего варианта использования.