Managing multiple repositories that serve distinct but interconnected purposes can be a challenging task π. This scenario is common when an organization wishes to contribute to an open-source project π while also maintaining an internal space for private collaboration π.
The challenge here lies in keeping these repositories in sync π without manual intervention, ensuring that changes made to one repository π are accurately reflected in the other π.
In this step-by-step tutorial π, we'll walk through a use case where a customer wants to contribute to an open-source project π» and, at the same time, collaborate internally within their organization π’.
We will:
- Changing the ownership of the existing repository. Follow this steps
- π΄ Create a fork of the open-source repository, providing the customer ownership and full control over this copy.
- ποΈ Set up an internal repository for private collaboration within the customer's organization.
- π€ Implement GitHub Actions to automatically keep these repositories in sync.
- π» Navigate to the open-source repository on GitHub.
βοΈ Click on the "Fork" button at the top-right corner to create a fork of the repository. This will be your customer's copy, where they can have owner-level permissions.
- π Create a new, empty repository in GitHub under your customer's organization account.
- β¬οΈ Clone the forked repository to your local machine.
git clone [email protected]:YourAccount/ForkedRepo.git
- π Add the internal repository as a remote.
git remote add internal [email protected]:CustomerOrg/InternalRepo.git
- π Push all branches and tags to the internal repository.
git push --all internal git push --tags internal
Create a GitHub Action in the internal repository to automatically push changes to the forked repository.
# .github/workflows/sync.yml name: Sync to Fork on: push: branches: - main jobs: sync: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: | git remote add fork [email protected]:YourAccount/ForkedRepo.git git push fork main
- π Similarly, create a GitHub Action in the forked repository to automatically pull changes from the original open-source repository.
# .github/workflows/pull.yml name: Pull from Original on: schedule: - cron: '0 0 * * *' jobs: pull: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: | git remote add upstream [email protected]:OriginalAccount/OriginalRepo.git git pull upstream main git push origin main
- π₯ Your customer can now collaborate internally on their internal repository.
- π Any push to the
main
branch will automatically get pushed to their forked open-source repository via GitHub Actions. - π Periodically, the forked repository will pull any new changes from the original open-source repository.
- π‘οΈ Ensure you've set up proper permissions and protection Rulesets on both the internal and forked repositories.
- π Review the GitHub Action logs periodically to ensure syncing is working as expected.
By following this guide π, you'll set up an efficient workflow βοΈ for managing dual repositories, making it easier for your customer to contribute to the open-source community β€οΈ while keeping internal developments private π.