The Forking Workflow is fundamentally different than other popular Git workflows. Instead of using a single server-side repository to act as the “central” codebase, it gives every developer their own server-side repository. This means that each contributor has not one, but two Git repositories: a private local one and a public server-side one. The Forking Workflow is most often seen in public open source projects. Show
The main advantage of the Forking Workflow is that contributions can be integrated without the need for everybody to push to a single central repository. Developers push to their own server-side repositories, and only the project maintainer can push to the official repository. This allows the maintainer to accept commits from any developer without giving them write access to the official codebase. The Forking Workflow typically follows a branching model based on the
Gitflow Workflow. This means that complete feature branches will be purposed for merge into the original project maintainer's repository. The result is a distributed workflow that provides a flexible way for large, organic teams
(including untrusted third-parties) to collaborate securely. This also makes it an ideal workflow for open source projects. How it worksAs in the other Git workflows, the Forking Workflow begins with an official public repository stored on a server. But when a new developer wants to start working on the project, they do not directly clone the official repository. Instead, they fork the official repository to create a copy of it on the server. This new copy serves as their personal public repository—no other developers are allowed to push to it, but they can pull changes from it (we’ll see why this is important in a moment). After they have created their server-side copy, the developer performs a When they're ready to publish a local commit, they push the commit to their own public repository—not the official one. Then, they file a pull request with the main repository, which lets the project maintainer know that an update is ready to be integrated. The pull request also serves as a convenient discussion thread if there are issues with the contributed code. The following is a step-by-step example of this workflow.
To integrate the feature into the official codebase, the maintainer pulls the contributor’s changes into their local repository, checks to make sure it doesn’t break the project, merges it into their local
It’s important to understand that the notion of an “official” repository in the Forking Workflow is merely a convention. In fact, the only thing that makes the official repository so official is that it’s the public repository of the project maintainer. Forking vs cloningIt's important to note that "forked" repositories and "forking" are not special operations. Forked repositories are created using the standard Branching in the Forking WorkflowAll of these personal public repositories are really just a convenient way to share branches with other developers. Everybody should still be using branches to isolate individual features, just like in the Feature Branch Workflow and the Gitflow Workflow. The only difference is how those branches get shared. In the Forking Workflow, they are pulled into another developer’s local repository, while in the Feature Branch and Gitflow Workflows they are pushed to the official repository. Fork a repositoryAll new developers to a Forking Workflow project need to fork the official repository. As previously stated, forking is just a standard Clone your forkNext each developer needs to clone their own public forked repository. They can do this with the familiar Assuming the use of Bitbucket to host these repositories, developers on a project should have their own Bitbucket account and they should clone their forked copy of the repository with:
Adding a remoteWhereas
other Git workflows use a single origin remote that points to the central repository, the Forking Workflow requires two remotes—one for the official repository, and one for the developer’s personal server-side repository. While you can call these remotes anything you want, a common convention is to use origin as the remote for your forked repository (this will be created automatically when you run
You’ll need to create the upstream remote yourself using the above command. This will let you easily keep your local repository up-to-date as the official project progresses. Note that if your upstream repository has authentication enabled (i.e., it's not open source), you'll need to supply a username, like so:
This requires users to supply a valid password before cloning or pulling from the official codebase. Working in a branch: making & pushing changesIn the developer's local copy of the forked repository they can edit code, commit changes, and create branches just like in other Git workflows: All of their changes will be entirely private until they push it to their public repository. And, if the official project has moved forward, they can access new commits with Since developers should be working in a dedicated feature branch, this should generally result in a fast-forward merge. Making a Pull RequestOnce a developer is ready to share their new feature, they need to do two things. First, they have to make their contribution accessible to other developers by pushing it to their public repository. Their origin remote should already be set up, so all they should have to do is the following:
This diverges from the other workflows in that the origin remote points to the developer’s personal server-side repository, not the main codebase. Second, they need to notify the project maintainer that they want to merge their feature into the official codebase. Bitbucket provides a “pull request” button that leads to a form asking you to specify which branch you want to merge into the official repository. Typically, you’ll want to integrate your SummaryTo recap, the Forking Workflow is commonly used in public open-source projects. Forking is a
The Forking Workflow helps a maintainer of a project open up the repository to contributions from any developer without having to manually manage authorization settings for each individual contributor. This gives the maintainer more of a "pull" style workflow. Most commonly used in open-source projects, the Forking Workflow can also be applied to private business workflows to give more authoritative control over what is merged into a release. This can be useful in teams that have Deploy Managers or strict release cycles. Unsure what workflow is right for you? Check out our comprehensive Git workflow comparison page. How do I submit a pull request from a fork GitHub?Creating a pull request from a fork. Navigate to the original repository where you created your fork.. Above the list of files, click Pull request.. On the Compare page, click compare across forks.. In the "base branch" drop-down menu, select the branch of the upstream repository you'd like to merge changes into.. How do I fork a repository and push code on GitHub?Step 1: Fork a Repository. Fork a copy of the repository you would like to work on.. Step 2: Install Git. ... . Step 3: Set Up Git. ... . Step 4: Clone the Forked Repository. ... . Step 5: Move to the Repository Directory. ... . Step 6: Add Your Changes. ... . Step 7: Commit Changes. ... . Step 8: Push the File back to GitHub.. How do I fork a pull request and make a repo?Find a project you want to contribute to.. Fork it.. Clone it to your local system.. Make a new branch.. Make your changes.. Push it back to your repo.. Click the Compare & pull request button.. Click Create pull request to open a new pull request.. How do you pull a remote fork branch?Introduction. Fork a GitHub repository: navigate to a repository on GitHub and click the Fork button.. Checkout a new branch (here called “new_feature”): git checkout -b new_feature.. Make desired changes to the local repository on this branch.. Pull new changes from remote: git checkout master , git pull upstream master .. |