Task is to
- Clone a public repository and store it locally
- Initialize a user's new repository(target) with the repository content that you downloaded locally.
The CLI commands work perfectly but I need to do it using python, and when I run this code, a github login dialogue box opens and I enter the credentials and then the push works but nothing is seen on the remote repository, can we push nothing?
I have tried using subprocess module too, it does not work. I have checked every other stackoverflow solution and did not find a working solution.I need a new solution or a correction to this asap. Thanks.
import git
git.Repo.clone_from('https://github.com/kristej/Uniform-Database-Management.git','Uniforms')
repo = git.Repo('Uniforms')
target_repo = "https://github.com/kristej/Jojorabit.git"
# List remotes
# Reference a remote by its name as part of the object
print(f'Remote name: {repo.remotes.origin.name}')
print(f'Remote URL: {repo.remotes.origin.url}')
# Delete a default remote if already present
if repo.remotes.origin.url != target_repo:
repo.delete_remote(repo.remotes.origin.name)
# Create a new remote
try:
remote = repo.create_remote('origin', url=target_repo)
except git.exc.GitCommandError as error:
print(f'Error creating remote: {error}')
# Reference a remote by its name as part of the object
print(f'Remote name: {repo.remotes.origin.name}')
print(f'Remote URL: {repo.remotes.origin.url}')
#Push changes
print(repo.git.push("origin", "HEAD:refs/for/master"))