0

Let's say I have:

 1. github repo https://github.com/user1/repo1

 2. And I have gitlab repo (user2)
    https://gitlab.com/user2/repo2

What I want to do is programmatically from my script push the latest code from repo1 to repo2

-Let's presume I always use login and password Auth, user1 and user2 have different passwords
-I don't want to save the original commit history of repo1(that's important). 
-Author of the commit in repo2 should be user2

It should work something like this:

I run my script(for example pusher.py), specifying input params:

user1, password1, user2, password2, origin1, origin2, commit_message

And my script

  1. Authorizes as user1, pulls code from repo1

  2. Logs out and authorizes as user2, commits and pushes to repo2 as user2

How do I do this? May be you can share the list of git commands to do it. Right now I am thinking of

1.Authenticating as user1, pulling repo, programmatically copying code to another folder. Logging out as suggested here

git credential-manager delete https://github.com/user1/repo1

2.Authenticating as user2 and committing and pushing to new repo

Is there a better to do this?

Community
  • 1
  • 1
user2950593
  • 9,233
  • 15
  • 67
  • 131
  • 1
    Can you access each repo with ssh and keys? If so, it would simplify the problem by using .ssh/config host entries. – Cole Tierney Jul 14 '19 at 13:33
  • I'm not sure how you would change the author of the commits, as Git is meant to keep traces of what really happened, not doctor the history in this way. Can you explain why you need to change the author? As asked, it seems like you're trying to change attribution of work to a different author, which seems fishy, but I assume you have a good reason to do it and I'd like to understand it. Without this author change part, it would be easy add two remotes, pull from one, push to the other. Each remote can be configured with its own credentials. – joanis Jul 14 '19 at 17:30
  • 1
    let's say i have development repo where i need full commits history and i have production repo. I don't wanna show to my customer all details of ongoing projects, only some really important benchmarks in production repo. (For example I want to push code only when he pays me money, but I want to have full commit history anywway in dev repo) – user2950593 Jul 15 '19 at 14:04
  • @user2950593 In this case, I would use a different approach, which we use at my work: for the public repo, I publish one big commit for the version. You can do this with a `git merge --squash`: that will merge in all the changes from the private repo, and let you create a single big commit on the public repo. – joanis Jul 15 '19 at 15:04
  • And actually, you could write a loop to do `git merge --squash` commit by commit, if there were commit details you wanted to keep. Since `git merge --squash` takes the changes but does not do the commit, you can write the commit history you want. Make sure you do it in a sandbox configured as `user2` and this might constitute an answer to your question. – joanis Jul 15 '19 at 15:06

0 Answers0