The Forking Workflow is a popular Git-based development strategy often used in open-source projects. It involves creating copies of the main project repository, allowing developers to make and test changes independently without affecting the original repository. Forking Workflow is ideal for large teams, contributors from outside the organization, and open-source projects where multiple developers work on independent features or bug fixes.
The Forking Workflow is distinct from other workflows (such as Gitflow) because it uses forks—independent copies of the main project repository on Git hosting platforms like GitHub or GitLab. Each developer can create a personal copy of the main repository (the “origin” repo) and work on features or fixes without affecting others. When ready, developers submit a pull request (PR) to propose their changes for inclusion in the original repository.
In the Forking Workflow, developers follow these steps:
This workflow ensures that developers’ work stays isolated until ready for integration, allowing the main repository to remain stable.
To start using the Forking Workflow, you’ll need access to a Git hosting platform. Here’s how to set it up.
On GitHub or GitLab, go to the original project repository. Click the Fork button to create a personal copy under your account.
After forking, you can clone the repository locally:
git clone https://github.com/your-username/project-name.git
This command downloads your forked repository to your local machine, allowing you to start making changes.
To stay updated with the main repository, add it as a remote named upstream:
cd project-name
git remote add upstream https://github.com/original-owner/project-name.git
origin
points to your fork.upstream
points to the original repositoryIn this section, we’ll explore the core steps involved in the Forking Workflow.
After forking, you clone the repository to your local machine. For instance
git clone https://github.com/your-username/project-name.git
This sets up a local copy where you can begin development.
In this workflow, it’s a best practice to create a new branch in your fork for each feature or bug fix. For example:
git checkout -b feature-login
Then make your changes, commit them, and push to your fork
git add .
git commit -m "Add login feature"
git push origin feature-login
feature-login
is a branch dedicated to the login feature, allowing organized work on a specific functionality.git commit -m "Add login feature"
: Confirms that changes have been saved.
git push origin feature-login
: Sends updates from feature-login
in your local repository to the corresponding branch in your fork on GitHub/GitLab.
Periodically, pull changes from the main repository to ensure your fork is up-to-date
git fetch upstream
git checkout main
git merge upstream/main
Explanation: git fetch upstream
retrieves changes from the main repo without altering your local branches. git merge upstream/main
applies these updates to your local main branch.
After finalizing your feature or fix, submit a pull request (PR).
In your PR description, provide context about your changes. The main repository maintainers will review, discuss, and eventually merge the PR if approved
The Forking Workflow is a powerful approach that prioritizes isolation, collaborative contributions, and code stability, making it the workflow of choice for open-source projects and distributed teams. Happy Coding!❤️