1

I want to mirror one of my repos into a privat one to make some non public changes but still getting updates from the public one. The problem with normal mirror is that all the time i update the privat repo my changes get deletet. Is there a way to fix this?

My idea was to make it like this:

Repo A is public and Repo B is privat. My privat repo has the branches main, repoA, my fixes. Now i want to mirror repo A into repo B branch repoA.

But this also destroyed branch my fixes all the time i tried updating.

  • 1
    What do you mean by "mirror"? Do you mean a "git clone"? If you "git clone" a repo, you can make changes to any branch and your changes won't be lost when you do a "git pull" to pull new changes from the original repo. Your changes will be merged with any changes from the original repo. – CryptoFool Mar 21 '21 at 13:46
  • Well i currently only tried this way: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository#mirroring-a-repository-in-another-location but all local references will be overwritten each time you fetch, – Daniel Hopp Mar 21 '21 at 13:56
  • Just don't use `--mirror`. Using that option is why you are having trouble. Read that page that you referenced above. It explains what the `--mirror` flag does. It does exactly that...it causes your changes to be blasted when you update from the original repo. You only use `--mirror`. when you want the copy to never differ at all from the original. But you want the copy to be different, containing your extra changes, but be able to be updated from the original. That's a normal `clone` with no `--mirror`. You might want to use `--bare` instead. That just avoids a local working directory. – CryptoFool Mar 21 '21 at 14:10
  • Okay, so i only have to git clone --bare https://github.com/exampleuser/repoA.git Clone the first repo and set push location to new repoB? git remote set-url --push origin https://github.com/exampleuser/repoB and then i can fetch and push new changes from repo a to repo b? – Daniel Hopp Mar 21 '21 at 16:59
  • Yip, exactly right. – CryptoFool Mar 21 '21 at 17:06
  • As you can see, I realized that my comment was complete enough to warrant being a true answer. – CryptoFool Mar 21 '21 at 17:16

2 Answers2

1

You don't want to use --mirror. Using that option is why you are having trouble. The --mirror option forces exactly the behavior you are seeing and don't want. It causes your changes to be blasted when you update from the original repo. You only use --mirror when you want the copy to never differ at all from the original (once updated).

In your case, you want to use --bare instead, as it will provide the part of the behavior of --mirror that you do want, that of creating just a copy of the underlying repository without a working directory. But unlike --mirror, --bare does not cause future changes to the copy to be lost when the copy is updated from the original. If you understand what a straight "clone" does with no behavior changing flags, then you know what --bare does. The --bare flag only affects the form that the repo takes on disk. It doesn't change anything about how updates are applied between repos.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
0

I know this question is a bit old, but I was having a similar issue and I think this is how to do it: https://github.com/marketplace/actions/github-repo-sync

This can be added the github actions, or you can explore the source code and see how they do it and do it yourself manually.

tgonzalez89
  • 621
  • 1
  • 6
  • 26