Collaborating on an open source project using the "fork and branch" workflow involves the following steps:
-
Fork the Repository: Start by navigating to the repository on the platform where it is hosted (e.g., GitHub) and click on the "Fork" button. This creates a copy of the repository under your GitHub account. Use this link below:
- Fork this repo: Fork this repository
-
Clone the Forked Repository: Once you have forked the repository, clone it to your local machine using the
git clone
command. This creates a local copy of the repository that you can work with.git clone <your-forked-repo-url>
-
Add the Original Repository as a Remote: To keep your forked repository in sync with the original repository, you need to add the original repository as a remote. Navigate to the cloned repository on your local machine using the
cd
command, and then add the remote using thegit remote
command:cd <cloned-repo-folder> git remote add upstream <original-repo-url>
-
Create a New Branch: Before making any changes, create a new branch in your local repository. This helps keep your changes isolated and organized. Use the
git branch
command followed by the branch name to create a new branch:git branch <branch-name>
-
Switch to the New Branch: Switch to the newly created branch using the
git checkout
command:git checkout <branch-name>
-
Make Changes and Commit: Make the necessary changes to the codebase in your local repository. Once you have made the desired changes, stage the changes using
git add
and commit them usinggit commit
:git add . git commit -m "Descriptive commit message"
-
Push Changes to Your Fork: Push the changes from your local branch to your forked repository on the remote server:
git push origin <branch-name>
-
Create a Pull Request: Go to your forked repository on the hosting platform (e.g., GitHub), switch to the branch you just pushed, and click on the "New Pull Request" button. This will allow you to submit your changes to the original repository for review.
-
Syncing with the Original Repository: Periodically, you may want to sync your forked repository with the changes made in the original repository. To do this, fetch the changes from the original repository using the remote you added earlier and then merge those changes into your local branch:
git fetch upstream git merge upstream/main # or upstream/master for older conventions
This will update your local branch with the latest changes from the original repository.
By following these steps, you can effectively collaborate on an open source project by forking the repository, creating a new branch, making changes, and submitting pull requests. It allows you to work on the project independently while keeping your changes separate from the original repository until they are reviewed and merged.
Check these out for more clarification: a. A Forked Repo b. Steps Used In Creating That Forked Repo