Cookie Preferences

We use cookies to enhance your experience. Choose your preference for cookie usage.

Essential cookies are required for basic functionality. Additional cookies help us improve our service and provide analytics.

View third-party services
  • Google Analytics: Website traffic analysis and conversion tracking
  • RudderStack: Analysis of user interactions with the website
  • Microsoft Clarity: User behavior analysis & session recordings
  • Facebook Pixel: Marketing analysis of user activity
Dev ToolsGitHub

Fork and pull request

Suppose you want to suggest changes to someone else's project or use someone else's project as a starting point for your own idea. If you are not a collaborator, you cannot modify files in the project's repo.

In this situation GitHub makes it possible for you to begin contributing. You need to fork this repo, modify its content, and propose your changes via pull request. If the project's owners like your work, they might put your changes into the original repository.

Forking a repo

A fork is a copy of a repository. It allows you to freely experiment with changes without affecting the original project. To make a fork, you must be logged into GitHub.

Please, open our educational repository and click Fork in the top-right corner of the page. Now you have a fork of the original repository. Find it on the Your repositories page (click by your profile).

It is important that a fork is just a regular repository hosted on GitHub like the original repo. You can add new files and modify or remove existing files in your fork.

Branching

Before we start making changes to the content of the repo, we need to understand an important concept called branching. It provides a way to work on different versions of a repository at the same time.

By default, any repository has a branch named master that represents the actual version of a project. If you want to change some content in a repo, first, you should create a new branch based on master to get an isolated snapshot of the project. Usually a branch represents a feature or a fix that is developed now. It allows you to protect master from possible bad changes and roll back. You can also create a new branch based on another branch (non-master) that is active.

Branching especially helps to organize team development processes. Several programmers work on different features at the same time, each in their own branch. After the work is completed, the code is merged together.

Now it may be hard for you to understand branching, just follow our recommendation and use special branches rather than working on the master directly. If you want to read more about branches, look at a small article written by GitHub.

Modifying contents in a special branch

Before we start modifying the content, let's create a new branch. Click the drop-down list with master branch and enter a unique descriptive name for your branch like edit-readme and then press Enter or click Create branch: name.

Let's modify the README.md file, which we can find in the new branch. Open this file and click the edit button (pencil) or click the same button below the repo. Make a change; for example, write some information you learned about forks or branches.

To apply these changes, scroll to the Commit changes section below, write a meaningful message about your changes, and then click Commit changes. It will put these changes in your repository in the edit-readme branch. The original repo and the master branch of your fork will not be changed.

Then look at the README.md file to see your changes.

You may perform several commits in the same branch with different changes to understand this process better. You can also create or upload a new file in this repo by clicking a button if you want.

In the next lessons, we will learn how to modify a repo's content using IntelliJ IDEA and Terminal instead of a web browser.

Pull request

After you change the content of a repo, you can create a pull request (PR) to propose your changes to the original repository. You may click Compare & pull request or New pull request as is shown below.

Then you will see a special page for creating pull request.

You may see the green text Able to merge which means that your version of the project does not have conflicts with the original repo's version. In some cases, the text might be different; that means the original repository has been changed, but you can still create a PR. In the next lessons, we will learn how to synchronize your fork with the original repository.

Make sure that the base fork is specified as the original repo (hyperskill/intro-to-github) with the master branch, and the head fork is your repo with a non-master branch.

Click Create pull request, enter a descriptive title, and then click Create pull request again. After that you will see the created PR in the project's repo (You may find it in the Pull requests section).

We will not respond to your requests in this repository, don't be surpised about that :)

Finally, we note that you can also create a completely new repository for a new project without forking. To do this, go to your repository and click New. Enter a descriptive name of your repository. You will have full access to this repository as an owner, so you do not need to fork it to make changes. If you want, you can play with your own repository.

How did you like the theory?
Report a typo