The code should do the following in order:
- It should download/clone the public Github repository locally.
- It should remove all the git history (and branches)
- Use the Github API to create a new Github repository initialized with the input github repository content that you downloaded locally. The new repository should be named using name supplied. I am able to do steps 1 and 3 but asks for log-in 2 times. I am not able to initialize the new remote repo with local repo. local_repo = repo1 how? And removing git history? where can I find git history in the cloned repo.
import git,os,tempfile,os,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!!")