The fork is the process of copying a remote repository. It is a method of creating a server-side copy of some other remote repository. A remote repository on GitHub(or any other Git hosting website) could be owned by some other developer, and we may not have the required permissions to make changes to it. But we can copy that GitHub repository to our own GitHub account.
By doing this we will become the owner of this copied or forked repository and we can then make changes to it. These changes will not be visible to the owner of the original repository but we can propose these changes to the author with the help of pull requests. Forking is usually done to contribute to open source projects. Let's learn how to fork a repository on GitHub.
How to Fork on GitHub?
As discussed above, forking is simply the process of making a copy of a remote repository. Forking on GitHub is a pretty straightforward process. Follow the steps below to fork a remote repository on GitHub.
- First, log in to your GitHub account and search for the repository that you want to copy in the search bar.
- Find the correct repository and open the repo's page on GitHub.
- On the top right corner, you will see a button with "fork" written on it. Click on this button to fork the repository to your GitHub account.
You will now be able to see this repository in your own GitHub account. You can clone this repository, commit changes and push it back to your forked remote repository.
You can also suggest some changes to the author of the original repository by creating a pull request.
Fork vs Clone
- This is a very common question that may arise when we first learn about forking.
- Forking and cloning both create a copy of a repository. The difference is that fork will create a remote copy on some Git hosting websites like GitHub or Bitbucket. But clone will create a copy of the repository on our local system and not on the remote server.
- Cloning is done by using the Git Clone command whereas the Git hosting websites provide the option to fork a remote repository.
- Git Fork is mostly used to contribute to open source projects whereas Git Clone is used when working on a project with other developers in a team.
- Cloning is the next step that we usually perform after forking. We will learn more about this in the forking workflow section given below.
A forking workflow is where each collaborator has a separate remote repository. This remote repository is forked from a central repository and only the project manager has the access to this repository. All other developers will be pushing to their individual remote repositories and the project manager can choose whether the changes are adequate or not and whether they should be merged into the central remote repository. These same steps are followed if a single developer wants to contribute to an open-source project. The steps involved in the forking workflow are described below.
- Each developer forks a central remote repository to get their own copy.
- The developers then clone their forked repositories to their local system. They can then work on their individual tasks, create new branches and add new commits on their local machine.
- The new commits and branches are then pushed to the developer's forked repository.
- Next, the developer will create a new pull request to share these changes with the project manager or the author of the original repository.
- If the changes do not cause any conflict and add value to the project, then the pull request is accepted and the changes are merged to the central remote repository.
Forking is the process of creating a copy of a remote repository on the server itself. This lets us make changes to a repository that is owned by someone else. However, these changes will only reflect on the forked repository and will not affect the original one. We can create a pull request and if the author likes our changes then he may merge them with the original repository. Forking is also not the same as cloning because cloning will create a local copy whereas forking will create a copy remote server itself. Forking workflow is very commonly used when contributing to open-source projects. It is also used in some organizations because in a forked workflow the central repository is not flooded with the changes of all the developers. Instead, the project manager can view and analyze the changes using pull requests and merge them with the original repository.