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.
- Navigate to
https://github.com/apache/incubator-answer
.
- 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:
-
Go to GitHub and create a new private repository duckyfoo/duckyfoo
.
-
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:
-
Fetch the latest changes from the upstream repository:
git fetch upstream
-
Merge the changes from the upstream repository into your local main branch:
git checkout main
git merge upstream/main
-
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.