gitgithubgitlabmirroring

Sync contributions between public GitHub repo and its private GitLab mirror


Background

I have a public repo on GitHub that stores the latest updates of my project.

┌───────────────┐        ┌───────────────┐           ┌────────────────┐
│               │        │               │           │                │
│    GitHub     │ Public │    GitHub     │  Private  │    GitLab      │
│               │ contrib│               │  contrib  │                │
│  Public fork  ◄────────►  Public repo  │x─────────x│ Private mirror │
│               │ Create │               │  Cannot   │                │
│  Downstream   │   PR   │   Upstream    │ create PR │   Downstream   │
│               │        │               │ (push/pull│                │
└───────────────┘        └───────────────┘  via local└────────────────┘
                                            machine)                   

The contributions are done publicly and privately:

As I said, I have a GitLab mirror. It means that I do not make any changes to the main branch there, I only pull the changes from upstream. I know that there are things like bidirectional mirror which can probably be used in my case but is usually advised against doing for CAP theorem as so on.

As a result, the workflow for private contributions (pushing the changes from the private mirror on GitLab to the public repo on GitHub) is as follows:

  1. In the private mirror on GitLab:
    • a. Sync the main branch with upstream
    • b. Create a new branch, make changes, and create an MR
    • c. Have the changes in the MR reviewed and approved
  2. Once the work on the MR is finished, I do the following:
    • a. Close the MR on GitLab
    • b. Pull the branch with changes on my local machine
    • c. Push the branch upstream to my public repo on GitHub via the local machine
    • d. Create and merge the PR on my public repo on GitHub

My questions

There are the following things that I don't like about my workflow:

  1. The MRs on GitLab are closed. I cannot merge them, because the GitLab repo is a mirror (I explained the reasons earlier). Can MRs be dealt with in a better or cleaner way?
  2. The step 2c ("Push the branch upstream to my public repo on GitHub via the local machine") is done manually. Can and should I automate this process? If yes, how can I do it?

Solution

    1. You can create two labels merged and abandoned to mark whether the MR was closed and merged on GitHub, or abandoned, respectively.

    2. I'm not sure what you mean. If you frequently need to do 2b and 2c together, you can write a script that perform these two steps: (assuming remotegitlab points to GitLab and remote github points to GitHub)

    #!/bin/bash
    
    git pull gitlab "$@" && git push github "$@"
    

    The script takes a branch name as its command line argument.