如何解决使用python Github将本地存储库推送到远程存储库
代码应按顺序执行以下操作:
- 它应该在本地下载/克隆公共Github存储库。
- 应删除所有git历史记录(和分支)
- 使用Github API创建新的Github存储库,已使用您在本地下载的输入github存储库内容进行了初始化。新的存储库应命名为 使用提供的名称。
我能够执行1和3,但要求登录2次。我无法使用本地存储库初始化新的远程存储库。 local_repo = repo1 如何? 并删除git历史记录?在哪里可以找到克隆存储库中的git历史记录。
import git,os,tempfile,fnmatch,sys
from github import Github
username = sys.argv[1]
password = sys.argv[2]
input_repo_url = sys.argv[3]
output_repo_name = sys.argv[4]
tempdir=tempfile.mkdtemp(prefix="",suffix="")
predictable_filename = "myfile"
saved_umask = os.umask(77)
path = os.path.join(tempdir,predictable_filename)
print("Cloning the repository at "+path)
local_repo = git.Repo.clone_from(input_repo_url,path,branch="master")
print("Clone successful!")
g = Github(username,password)
user = g.get_user()
repo1 = user.create_repo(output_repo_name)
print("New repository created at "+username+" account ")
print(repo1)
target_url = "https://github.com/"+username+"/"+output_repo_name+".git"
print(target_url)
print("Pushing cloned repo to target repo")
local_repo.create_remote("new",url=target_url)
local_repo.git.push("new")
print("Success!!")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。