Github Private Project with Upstream OSS dependency

Viewed 7

i need to use a public open source project, https://github.com/apache/incubator-answer, as the basis for my new private project, https://github.com/duckyfoo/duckyfoo.

I want to be able to merge changes from https://github.com/apache/incubator-answer to https://github.com/duckyfoo/duckyfoo when it makes sense.

I want to be able to work on https://github.com/duckyfoo/duckyfoo and not have those changes go back to https://github.com/apache/incubator-answer

I sometimes want to be able to submit changes to https://github.com/apache/incubator-answer to help out the open source project.

How can I set this all up?

2 Answers

The eternal quest for freedom and flexibility!

You want to create a private GitHub project (https://github.com/duckyfoo/duckyfoo) that uses a public open-source project (https://github.com/apache/incubator-answer) as its basis, while still being able to maintain your own changes and sometimes contribute to the original project. You want to be able to merge changes from the original project into your private project, but not the other way around. You also want to be able to submit changes from your private project to the original project if desired.

To achieve this, you'll need to follow these steps:

  1. Fork the original project:
    Create a copy of the original project (https://github.com/apache/incubator-answer) by clicking the "Fork" button on the original project's page. This will create a new repository with the same code and history. Name your fork, for example, "https://github.com/duckyfoo/incubator-answer-fork".
  2. Clone and modify your fork:
    Clone your forked repository to your local machine using git clone or some other Git client. This will give you a copy of the forked repository on your local machine.
  3. Create your private project:
    Create a new, empty repository on GitHub for your private project (https://github.com/duckyfoo/duckyfoo). Initialize a new Git repository using git init and add your modified fork as a remote repository using git remote add or git folder.
  4. Merge changes from your fork to your private project:
    Use git pull to merge changes from your forked repository to your private project. You can do this periodically to keep your private project up-to-date with the latest changes from the original project.
  5. Commit and push changes to your private project:
    Make changes to your private project and commit them using git commit. Push your changes to your private repository using git push.
  6. Submit changes to the original project (optional):
    When you've made changes to your private project that you'd like to contribute to the original project, create a pull request from your private project to the original project. This will allow you to submit your changes to the original project.
  7. Use a workflow to manage updates:
    To simplify the process of merging changes from your fork to your private project, you can set up a Git Flow-like workflow using git subtree or a tool like git-sync. This will automate the process of merging changes and keep your private project up-to-date with the original project.
  8. Keep your fork updated:
    Periodically merge changes from your fork to your local machine, then push those changes to your private project. This will ensure that your private project stays up-to-date with the original project.

Here's a basic workflow you can follow:

          +---------------+
          |  Original  |
          |  Project     |
          +---------------+
                  |
                  |  Fork
                  v
          +---------------+
          |  Forked      |
          |  Repository  |
          +---------------+
                  |
                  |  Clone
                  v
          +---------------+
          |  Local        |
          |  Machine     |
          +---------------+
                  |
                  |  Private  |
                  |  Project  |
                  v
          +---------------+
          |  Private  |
          |  Repository  |
          +---------------+

By following these steps, you'll be able to use the original project as a base for your private project, while still being able to maintain your own changes and contribute to the original project if desired.

To set up a workflow that allows you to work on a private project with an upstream open-source dependency while maintaining the ability to merge changes from the upstream repository, contribute back to it, and keep your private changes separate, you can follow these steps:

1. Fork the Upstream Repository

First, fork the upstream open-source project (https://github.com/apache/incubator-answer) to your own GitHub account. This will allow you to make contributions to the upstream project.

  1. Navigate to https://github.com/apache/incubator-answer.
  2. Click on the "Fork" button in the upper right corner. This will create a copy of the repository under your own GitHub account (let’s assume https://github.com/yourusername/incubator-answer).

2. Clone the Forked Repository Locally

Next, clone your forked repository to your local machine:

git clone https://github.com/yourusername/incubator-answer
cd incubator-answer

3. Set the Remote to the Upstream Repository

Add the original repository as a remote named upstream:

git remote add upstream https://github.com/apache/incubator-answer

4. Create Your Private Project Repository

Create your private project on GitHub (https://github.com/duckyfoo/duckyfoo). Initialize it if you haven't already:

  1. Go to GitHub and create a new private repository duckyfoo/duckyfoo.

  2. Clone this private repository to your local machine:

    git clone https://github.com/duckyfoo/duckyfoo
    cd duckyfoo
    

5. Implement the Initial Setup for the Private Project

In the local directory of your private project, add your forked repository as a remote:

git remote add basis https://github.com/yourusername/incubator-answer

6. Pull the Basis Project into Your Private Repository

Pull the content of your forked repository into your private repository:

git pull basis main

7. Create a Separate Branch for Making Changes to the Upstream Repository

When you need to contribute to the upstream repository, create a separate branch that will be used for upstream contributions:

git checkout -b contribute-to-upstream

Make your changes and commit them. Then push the branch to your fork:

git push origin contribute-to-upstream

Create a pull request from this branch to the upstream repository (https://github.com/apache/incubator-answer) from your fork.

8. Merging Upstream Changes into Your Private Project

Periodically, you will want to pull changes from the upstream (original) repository into your private project. To do this, follow these steps:

  1. Fetch the latest changes from the upstream repository:

    git fetch upstream
    
  2. Merge the changes from the upstream repository into your local main branch:

    git checkout main
    git merge upstream/main
    
  3. Resolve any merge conflicts if they arise, commit the merge, and push the updated main branch to your private repository:

    git push origin main
    

Summary of Commands

Here’s a summary of the main commands for different tasks:

  • Fork upstream and clone locally:

    git clone https://github.com/yourusername/incubator-answer
    cd incubator-answer
    git remote add upstream https://github.com/apache/incubator-answer
    
  • Clone private project:

    git clone https://github.com/duckyfoo/duckyfoo
    cd duckyfoo
    git remote add basis https://github.com/yourusername/incubator-answer
    git pull basis main
    
  • Contribute changes to upstream:

    git checkout -b contribute-to-upstream
    # Make changes
    git push origin contribute-to-upstream
    # Create a pull request to `https://github.com/apache/incubator-answer` from your fork
    
  • Merge upstream changes into your private project:

    git fetch upstream
    git checkout main
    git merge upstream/main
    git push origin main
    

By following these steps, you will be able to work on your private project, keep it updated with changes from the upstream open-source project, and contribute back to the open-source project when needed.