Table of Contents

Forking in Git

When contributing to an open-source project, you will not be able to make the changes directly to the project. Only the repository maintainers have that privilege.

What you need to do instead is to fork the specific repository, make the changes to the forked project and then submit a pull request to the original project. You will learn more about pull requests in the next chapters.

If you clone a repository that you don't have the access to and then try to push the changes directly to that repository, you would get the following error:

ERROR: Permission to laravel/laravel.git denied to bobbyiliev.
Fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This is where Forks come into play!

In order to fork a repository, you need to visit the repository via your browser and click on the Fork button on the top right:

Fork a repository

Then choose the account that you want to fork the repository to:

Choose an account to fork the repository under

Then it might take a few seconds for the repository to be forked under your account:

Forking the repository

With that, you would have an exact copy of the repository in question under your account.

The benefit here is that you can now clone the forked repository under your account, make the changes to that repository as normal, and then once you are ready, you can submit a pull request to the original repository contributing your changes.

As we've now mentioned submitting pull requests a few times already, let's go ahead and learn more about pull requests in the next chapter!