1

I have two similar Git repositories. One is hosted on GitHub, called myrepo_github; and another one is hosted on GitLab; called myrepo_gitlab. The two repositories are similar in the sense that they are frequently merged in our company, and they have the same copy for some corresponding commits.

Now I need to incorporate all changes I have made in myrepo_github to myrepo_gitlab. What are the commands to do this task?

I do not need to transfer all histories of my commits, but only the final changes I have made in all files that I have touched. My question may not be clear, but any inputs are welcome.

zell
  • 9,830
  • 10
  • 62
  • 115

1 Answers1

3

Git is decentralized. While 99% of the time we are working on a remote called origin you can add multiple remotes and work on them. Add a separate remote with the url pointing to the second (remote) repository location and work on it normally by adding the remote name when referencing stuff.

git clone https://something/myrepo_gitlab dir
cd dir
# git remote -v  # origin points to myrepo_gitlab
git remote add myrepo_github https://something/myrepo_github
git fetch myrepo_github
git pull myrepo_github master  # or rebase or pull --rebase
git push origin master
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • Thank you! How can I incorporate *only* changes I have made? The one above seems to incorporate *all* changes into a new repo? – zell May 10 '21 at 13:01
  • For example find the commits only you made and cherry pick them. – KamilCuk May 10 '21 at 13:15
  • How can I use git fetch myrepo_github while cherry picking my own commits? I searched Google in vain. – zell May 10 '21 at 13:47
  • `How can I use git fetch myrepo_github while cherry picking my own commits?` I do not understand, these are 2 separate operations. You cannot use git fetch at the same time as cherry picking, because one operation will lock `.git` directory, you can use one after another. You can specify revisions for cherry-pick as explained in `man gitrevisions` – KamilCuk May 10 '21 at 13:52
  • Why not use GitLab's mirroring feature? – Arihant Godha May 11 '21 at 03:56